diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/GenerateCommand.cs b/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/GenerateCommand.cs index 637421409d..ba38782ceb 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/GenerateCommand.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/GenerateCommand.cs @@ -214,24 +214,27 @@ namespace Microsoft.AspNetCore.Razor.Tools foreach (var result in results) { var errorCount = result.CSharpDocument.Diagnostics.Count; - if (errorCount > 0) + for (var i = 0; i < errorCount; i++) { - success = false; - - for (var i = 0; i < errorCount; i++) + var error = result.CSharpDocument.Diagnostics[i]; + if (error.Severity == RazorDiagnosticSeverity.Error) + { + success = false; + } + + if (i < 100) { - var error = result.CSharpDocument.Diagnostics[i]; Error.WriteLine(error.ToString()); // Only show the first 100 errors to prevent massive string allocations. if (i == 99) { - Error.WriteLine($"And {errorCount - i + 1} more errors."); - break; + Error.WriteLine($"And {errorCount - i + 1} more warnings/errors."); } } } - else + + if (success) { // Only output the file if we generated it without errors. var outputFilePath = result.InputItem.OutputPath; diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/src/DotnetToolTask.cs b/src/Razor/Microsoft.NET.Sdk.Razor/src/DotnetToolTask.cs index 79694479a4..9a660fb1bf 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/src/DotnetToolTask.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/src/DotnetToolTask.cs @@ -165,6 +165,17 @@ namespace Microsoft.AspNetCore.Razor.Tasks { // Server execution succeeded. Log.LogMessage(StandardOutputLoggingImportance, $"Server execution completed with return code {result}."); + + // There might still be warnings in the error output. + if (LogStandardErrorAsError) + { + LogErrors(completedResponse.ErrorOutput); + } + else + { + LogMessages(completedResponse.ErrorOutput, StandardErrorLoggingImportance); + } + return true; } else if (result == 2) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs index 8a5d449cc7..2138f539ac 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs @@ -45,6 +45,24 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs"); } + [Fact] + [InitializeTestProject("ComponentApp")] + public async Task Build_Successful_WhenThereAreWarnings() + { + ReplaceContent("", "Components", "Pages", "Index.razor"); + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result, allowWarnings: true); + + Assert.FileExists(result, OutputPath, "ComponentApp.dll"); + Assert.FileExists(result, OutputPath, "ComponentApp.pdb"); + + // Verify component compilation succeeded + Assert.AssemblyContainsType(result, Path.Combine(OutputPath, "ComponentApp.dll"), "ComponentApp.Components.Pages.Counter"); + + Assert.BuildWarning(result, "RZ10014"); + } + [Fact] [InitializeTestProject("ComponentLibrary")] public async Task Build_WithoutRazorLangVersion_ProducesWarning() diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/RazorGenerateIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/RazorGenerateIntegrationTest.cs index 646c21cc77..e9d436b354 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/RazorGenerateIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/RazorGenerateIntegrationTest.cs @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildFailed(result); - Assert.BuildOutputContainsLine(result, "And 101 more errors."); + Assert.BuildOutputContainsLine(result, "And 101 more warnings/errors."); // RazorGenerate should compile the assembly, but not the views. Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.dll"); diff --git a/src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor b/src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor index 16dac31925..73d0d8b8f7 100644 --- a/src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor +++ b/src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor @@ -2,4 +2,4 @@

Hello, world!

-Welcome to your new app. +Welcome to your new app. \ No newline at end of file