From 34f78994d1220b81c6e2732f3181aac2593dcdc5 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 29 Jan 2016 21:07:02 -0800 Subject: [PATCH] Infer the analyzer languageId from compilerName Simplifies using a different compiler since you only have to set one value if the the compiler is known to dotnet-compile --- .../commands/dotnet-compile/CompilerUtil.cs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/dotnet/commands/dotnet-compile/CompilerUtil.cs b/src/dotnet/commands/dotnet-compile/CompilerUtil.cs index 6f888a916..962046303 100644 --- a/src/dotnet/commands/dotnet-compile/CompilerUtil.cs +++ b/src/dotnet/commands/dotnet-compile/CompilerUtil.cs @@ -26,12 +26,29 @@ namespace Microsoft.DotNet.Tools.Compiler return compilerName; } - + + private static readonly KeyValuePair[] s_compilerNameToLanguageId = + { + new KeyValuePair("csc", "cs"), + new KeyValuePair("vbc", "vb"), + new KeyValuePair("fsc", "fs") + }; + public static string ResolveLanguageId(ProjectContext context) { var languageId = context.ProjectFile.AnalyzerOptions?.LanguageId; - languageId = languageId ?? "cs"; - + if (languageId == null) + { + var compilerName = ResolveCompilerName(context); + foreach (var kvp in s_compilerNameToLanguageId) + { + if (kvp.Key == compilerName) + { + languageId = kvp.Value; + } + } + } + return languageId; }