Skip to content

Report msbuild diagnostics as warnings/errors. #43571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ public IncrementalMSBuildWorkspace(IReporter reporter)
{
WorkspaceFailed += (_sender, diag) =>
{
// Errors reported here are not fatal, an exception would be thrown for fatal issues.
reporter.Verbose($"MSBuildWorkspace warning: {diag.Diagnostic}");
// Report both Warning and Failure as warnings.
// MSBuildProjectLoader reports Failures for cases where we can safely continue loading projects
// (e.g. non-C#/VB project is ignored).
// https://github.com/dotnet/roslyn/issues/75170
reporter.Warn($"msbuild: {diag.Diagnostic}", "⚠");
};

_reporter = reporter;
Expand Down
21 changes: 21 additions & 0 deletions test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ public async Task BlazorWasm()
//await App.AssertOutputLineStartsWith(MessageDescriptor.HotReloadSucceeded);
}

[Fact]
public async Task BlazorWasm_MSBuildWarning()
{
var testAsset = TestAssets
.CopyTestAsset("WatchBlazorWasm")
.WithSource()
.WithProjectChanges(proj =>
{
proj.Root.Descendants()
.Single(e => e.Name.LocalName == "ItemGroup")
.Add(XElement.Parse("""
<AdditionalFiles Include="Pages\Index.razor" />
"""));
});

App.Start(testAsset, [], testFlags: TestFlags.MockBrowser);

await App.AssertOutputLineStartsWith("dotnet watch ⚠ msbuild: [Warning] Duplicate source file");
await App.AssertWaitingForChanges();
}

// Test is timing out on .NET Framework: https://github.com/dotnet/sdk/issues/41669
[CoreMSBuildOnlyFact]
public async Task HandleMissingAssemblyFailure()
Expand Down
12 changes: 8 additions & 4 deletions test/dotnet-watch.Tests/Watch/Utilities/WatchableApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ public async Task<string> AssertOutputLineStartsWith(string expectedPrefix, Pred
success: line => line.StartsWith(expectedPrefix, StringComparison.Ordinal),
failure: failure ?? new Predicate<string>(line => line.Contains(WatchErrorOutputEmoji, StringComparison.Ordinal)));

if (line == null && failure != null)
if (line == null)
{
Assert.Fail($"Failed to find expected text: '{expectedPrefix}'");
Assert.Fail(failure != null
? "Encountered failure condition"
: $"Failed to find expected prefix: '{expectedPrefix}'");
}
else
{
Assert.StartsWith(expectedPrefix, line, StringComparison.Ordinal);
}

Assert.StartsWith(expectedPrefix, line, StringComparison.Ordinal);

return line.Substring(expectedPrefix.Length);
}
Expand Down
Loading