From 72665a4f9fb787c057773c559262c1ae13efc7d2 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Sun, 25 Oct 2015 23:37:41 -0700 Subject: [PATCH] Remove compiler name autodetection Also add compilerName: csc to every project.json to compensate. --- src/Microsoft.DotNet.Cli.Utils/project.json | 1 + src/Microsoft.DotNet.Cli/project.json | 1 + .../project.json | 1 + .../Program.cs | 53 +------------------ .../project.json | 1 + .../project.json | 1 + .../project.json | 1 + .../project.json | 2 +- 8 files changed, 9 insertions(+), 52 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/project.json b/src/Microsoft.DotNet.Cli.Utils/project.json index b6ff1d85e..e177c12c2 100644 --- a/src/Microsoft.DotNet.Cli.Utils/project.json +++ b/src/Microsoft.DotNet.Cli.Utils/project.json @@ -1,5 +1,6 @@ { "version": "1.0.0-*", + "compilerName": "csc", "shared": "**/*.cs", diff --git a/src/Microsoft.DotNet.Cli/project.json b/src/Microsoft.DotNet.Cli/project.json index b927627b4..d6a128e4f 100644 --- a/src/Microsoft.DotNet.Cli/project.json +++ b/src/Microsoft.DotNet.Cli/project.json @@ -1,6 +1,7 @@ { "name": "dotnet", "version": "1.0.0-*", + "compilerName": "csc", "compilationOptions": { "emitEntryPoint": true }, diff --git a/src/Microsoft.DotNet.Tools.Compiler.Csc/project.json b/src/Microsoft.DotNet.Tools.Compiler.Csc/project.json index 37137989e..9a2f3d0eb 100644 --- a/src/Microsoft.DotNet.Tools.Compiler.Csc/project.json +++ b/src/Microsoft.DotNet.Tools.Compiler.Csc/project.json @@ -1,6 +1,7 @@ { "name": "dotnet-compile-csc", "version": "1.0.0-*", + "compilerName": "csc", "compilationOptions": { "emitEntryPoint": true }, diff --git a/src/Microsoft.DotNet.Tools.Compiler/Program.cs b/src/Microsoft.DotNet.Tools.Compiler/Program.cs index cea220dba..2119009fe 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/Program.cs +++ b/src/Microsoft.DotNet.Tools.Compiler/Program.cs @@ -191,9 +191,9 @@ namespace Microsoft.DotNet.Tools.Compiler } var compilerName = context.ProjectFile.CompilerName; - if (compilerName == null && !TryDetectCompilerName(sourceFiles, out compilerName)) + if (compilerName == null) { - Console.Error.WriteLine("Could not detect the compiler name. Please specify it in the project.json file."); + Console.Error.WriteLine("Could not find the compiler name. Please specify it in the project.json file."); return false; } @@ -242,55 +242,6 @@ namespace Microsoft.DotNet.Tools.Compiler return success; } - private static readonly KeyValuePair[] s_compilerNameLookupTable = - { - new KeyValuePair(".cs", "csc"), - new KeyValuePair(".vb", "vbc"), - new KeyValuePair(".fs", "fsc") - }; - - /// - /// Uses the extension on the source files to try to detect the - /// compiler. If the source files have different extensions or the - /// extension is not recognized, returns false. - /// - private static bool TryDetectCompilerName(IEnumerable sourceFiles, out string compilerName) - { - compilerName = null; - string extension = null; - foreach (var file in sourceFiles) - { - if (!Path.HasExtension(file)) - { - return false; - } - - var tmpExtension = Path.GetExtension(file); - extension = extension ?? tmpExtension; - - if (extension != tmpExtension) - { - return false; - } - } - - if (extension == null) - { - return false; - } - - foreach (var kvp in s_compilerNameLookupTable) - { - if (extension == kvp.Key) - { - compilerName = kvp.Value; - return true; - } - } - - return false; - } - private static void PrintSummary(List diagnostics) { Reporter.Output.Writer.WriteLine(); diff --git a/src/Microsoft.DotNet.Tools.Compiler/project.json b/src/Microsoft.DotNet.Tools.Compiler/project.json index 60777510f..1d0c647b9 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/project.json +++ b/src/Microsoft.DotNet.Tools.Compiler/project.json @@ -1,6 +1,7 @@ { "name": "dotnet-compile", "version": "1.0.0-*", + "compilerName": "csc", "compilationOptions": { "emitEntryPoint": true }, diff --git a/src/Microsoft.DotNet.Tools.Publish/project.json b/src/Microsoft.DotNet.Tools.Publish/project.json index c0d8ddb35..c663ad76c 100644 --- a/src/Microsoft.DotNet.Tools.Publish/project.json +++ b/src/Microsoft.DotNet.Tools.Publish/project.json @@ -1,6 +1,7 @@ { "name": "dotnet-publish", "version": "1.0.0-*", + "compilerName": "csc", "compilationOptions": { "emitEntryPoint": true }, diff --git a/src/Microsoft.DotNet.Tools.Resgen/project.json b/src/Microsoft.DotNet.Tools.Resgen/project.json index da64c8872..52bbc0388 100644 --- a/src/Microsoft.DotNet.Tools.Resgen/project.json +++ b/src/Microsoft.DotNet.Tools.Resgen/project.json @@ -1,6 +1,7 @@ { "name": "resgen", "version": "1.0.0-*", + "compilerName": "csc", "compilationOptions": { "emitEntryPoint": true }, diff --git a/src/Microsoft.Extensions.ProjectModel/project.json b/src/Microsoft.Extensions.ProjectModel/project.json index c17c5cd2f..c203f4053 100644 --- a/src/Microsoft.Extensions.ProjectModel/project.json +++ b/src/Microsoft.Extensions.ProjectModel/project.json @@ -1,7 +1,7 @@ { "version": "1.0.0-*", "description": "Types to model a .NET Project", - + "compilerName": "csc", "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23419", "System.Collections": "4.0.11-beta-23419",