diff --git a/src/Microsoft.DotNet.ProjectModel/ErrorCodes.DotNet.cs b/src/Microsoft.DotNet.ProjectModel/ErrorCodes.DotNet.cs index d4cabc6f2..7389836dd 100644 --- a/src/Microsoft.DotNet.ProjectModel/ErrorCodes.DotNet.cs +++ b/src/Microsoft.DotNet.ProjectModel/ErrorCodes.DotNet.cs @@ -7,5 +7,8 @@ namespace Microsoft.Extensions.ProjectModel { // Target framework not installed public static readonly string DOTNET1011 = nameof(DOTNET1011); + + // Reference assemblies location not specified + public static readonly string DOTNET1012 = nameof(DOTNET1012); } } diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index f1058cdf8..2f1979fed 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -171,20 +171,36 @@ namespace Microsoft.Extensions.ProjectModel DiagnosticMessageSeverity.Warning)); } - if (requiresFrameworkAssemblies && !frameworkReferenceResolver.IsInstalled(TargetFramework)) + if (requiresFrameworkAssemblies) { var frameworkInfo = Project.GetTargetFramework(TargetFramework); - - // If there was an attempt to use reference assemblies but they were not installed - // report an error - diagnostics.Add(new DiagnosticMessage( - ErrorCodes.DOTNET1011, - $"Framework not installed: {TargetFramework.DotNetFrameworkName}", - filePath: Project.ProjectFilePath, - severity: DiagnosticMessageSeverity.Error, - startLine: frameworkInfo.Line, - startColumn: frameworkInfo.Column - )); + + if (string.IsNullOrEmpty(ReferenceAssembliesPath)) + { + // If there was an attempt to use reference assemblies but they were not installed + // report an error + diagnostics.Add(new DiagnosticMessage( + ErrorCodes.DOTNET1012, + $"The reference assemblies directory was not specified. You can set the location using the DOTNET_REFERENCE_ASSEMBLIES_PATH environment variable.", + filePath: Project.ProjectFilePath, + severity: DiagnosticMessageSeverity.Error, + startLine: frameworkInfo.Line, + startColumn: frameworkInfo.Column + )); + } + else if (!frameworkReferenceResolver.IsInstalled(TargetFramework)) + { + // If there was an attempt to use reference assemblies but they were not installed + // report an error + diagnostics.Add(new DiagnosticMessage( + ErrorCodes.DOTNET1011, + $"Framework not installed: {TargetFramework.DotNetFrameworkName} in {ReferenceAssembliesPath}", + filePath: Project.ProjectFilePath, + severity: DiagnosticMessageSeverity.Error, + startLine: frameworkInfo.Line, + startColumn: frameworkInfo.Column + )); + } } // Create a library manager diff --git a/src/Microsoft.DotNet.Tools.Compiler/Program.cs b/src/Microsoft.DotNet.Tools.Compiler/Program.cs index cc73ea2e3..01d14d4bc 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/Program.cs +++ b/src/Microsoft.DotNet.Tools.Compiler/Program.cs @@ -108,11 +108,6 @@ namespace Microsoft.DotNet.Tools.Compiler // Create the library exporter var exporter = context.CreateExporter(configuration); - var diagnostics = new List(); - - // Collect dependency diagnostics - diagnostics.AddRange(context.LibraryManager.GetAllDiagnostics()); - // Gather exports for the project var dependencies = exporter.GetDependencies().ToList(); @@ -151,6 +146,29 @@ namespace Microsoft.DotNet.Tools.Compiler Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}"); var sw = Stopwatch.StartNew(); + var diagnostics = new List(); + var missingFrameworkDiagnostics = new List(); + + // Collect dependency diagnostics + foreach (var diag in context.LibraryManager.GetAllDiagnostics()) + { + if (diag.ErrorCode == ErrorCodes.DOTNET1011 || + diag.ErrorCode == ErrorCodes.DOTNET1012) + { + missingFrameworkDiagnostics.Add(diag); + } + + diagnostics.Add(diag); + } + + if (missingFrameworkDiagnostics.Count > 0) + { + // The framework isn't installed so we should short circuit the rest of the compilation + // so we don't get flooded with errors + PrintSummary(missingFrameworkDiagnostics, sw); + return false; + } + // Dump dependency data // TODO: Turn on only if verbose, we can look at the response // file anyways @@ -240,11 +258,6 @@ namespace Microsoft.DotNet.Tools.Compiler }) .Execute(); - foreach (var diag in diagnostics) - { - PrintDiagnostic(diag); - } - var success = result.ExitCode == 0; if (success && compilationOptions.EmitEntryPoint.GetValueOrDefault()) @@ -255,10 +268,7 @@ namespace Microsoft.DotNet.Tools.Compiler runtimeContext.CreateExporter(configuration)); } - PrintSummary(success, diagnostics); - - Reporter.Output.WriteLine($"Time elapsed {sw.Elapsed}"); - Reporter.Output.WriteLine(); + PrintSummary(diagnostics, sw, success); return success; } @@ -423,14 +433,16 @@ namespace Microsoft.DotNet.Tools.Compiler return "\"" + input.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; } - private static void PrintSummary(bool success, List diagnostics) + private static void PrintSummary(List diagnostics, Stopwatch sw, bool success = true) { + PrintDiagnostics(diagnostics); + Reporter.Output.WriteLine(); var errorCount = diagnostics.Count(d => d.Severity == DiagnosticMessageSeverity.Error); var warningCount = diagnostics.Count(d => d.Severity == DiagnosticMessageSeverity.Warning); - if (errorCount > 0) + if (errorCount > 0 || !success) { Reporter.Output.WriteLine("Compilation failed.".Red()); } @@ -443,6 +455,9 @@ namespace Microsoft.DotNet.Tools.Compiler Reporter.Output.WriteLine($" {errorCount} Error(s)"); Reporter.Output.WriteLine(); + + Reporter.Output.WriteLine($"Time elapsed {sw.Elapsed}"); + Reporter.Output.WriteLine(); } private static bool AddResources(Project project, List compilerArgs, string intermediateOutputPath) @@ -553,6 +568,14 @@ namespace Microsoft.DotNet.Tools.Compiler return null; } + private static void PrintDiagnostics(List diagnostics) + { + foreach (var diag in diagnostics) + { + PrintDiagnostic(diag); + } + } + private static void PrintDiagnostic(DiagnosticMessage diag) { switch (diag.Severity)