Remove compiler name autodetection

Also add compilerName: csc to every project.json to compensate.
This commit is contained in:
Andy Gocke 2015-10-25 23:37:41 -07:00
parent 2ccecbf78e
commit 72665a4f9f
8 changed files with 9 additions and 52 deletions

View file

@ -1,5 +1,6 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"compilerName": "csc",
"shared": "**/*.cs", "shared": "**/*.cs",

View file

@ -1,6 +1,7 @@
{ {
"name": "dotnet", "name": "dotnet",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilerName": "csc",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
}, },

View file

@ -1,6 +1,7 @@
{ {
"name": "dotnet-compile-csc", "name": "dotnet-compile-csc",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilerName": "csc",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
}, },

View file

@ -191,9 +191,9 @@ namespace Microsoft.DotNet.Tools.Compiler
} }
var compilerName = context.ProjectFile.CompilerName; 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; return false;
} }
@ -242,55 +242,6 @@ namespace Microsoft.DotNet.Tools.Compiler
return success; return success;
} }
private static readonly KeyValuePair<string, string>[] s_compilerNameLookupTable =
{
new KeyValuePair<string, string>(".cs", "csc"),
new KeyValuePair<string, string>(".vb", "vbc"),
new KeyValuePair<string, string>(".fs", "fsc")
};
/// <summary>
/// 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.
/// </summary>
private static bool TryDetectCompilerName(IEnumerable<string> 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<DiagnosticMessage> diagnostics) private static void PrintSummary(List<DiagnosticMessage> diagnostics)
{ {
Reporter.Output.Writer.WriteLine(); Reporter.Output.Writer.WriteLine();

View file

@ -1,6 +1,7 @@
{ {
"name": "dotnet-compile", "name": "dotnet-compile",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilerName": "csc",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
}, },

View file

@ -1,6 +1,7 @@
{ {
"name": "dotnet-publish", "name": "dotnet-publish",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilerName": "csc",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
}, },

View file

@ -1,6 +1,7 @@
{ {
"name": "resgen", "name": "resgen",
"version": "1.0.0-*", "version": "1.0.0-*",
"compilerName": "csc",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
}, },

View file

@ -1,7 +1,7 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"description": "Types to model a .NET Project", "description": "Types to model a .NET Project",
"compilerName": "csc",
"dependencies": { "dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23419", "Microsoft.CSharp": "4.0.1-beta-23419",
"System.Collections": "4.0.11-beta-23419", "System.Collections": "4.0.11-beta-23419",