dotnet / dotnet/roslyn

MSBuildWorkspace reports warnings as errors/failures

Open
#75,182 1 comment 1 reaction 1 assignee Claimed by @jasonmalinowski View on GitHub
Area-IDE
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**: Roslyn 4.11.0

**Steps to Reproduce**:

Run this code:

```c#
using Microsoft.CodeAnalysis.MSBuild;

var workspace = MSBuildWorkspace.Create();

var project = await workspace.OpenProjectAsync(@"..\..\..\..\project\project.csproj");

foreach (var diagnostic in workspace.Diagnostics)
{
Console.WriteLine($"{diagnostic.Kind}: {diagnostic.Message}");
}
```

Where project.csproj is:

```csproj


net8.0
enable
enable



```

**Expected Behavior**:

The workspace reports the `NU1903` warning about a vulnerability as a warning, i.e. the output should be:

```
Warning: Msbuild failed when processing the file 'C:\src\tmp\roslynworkspaceapp\project\project.csproj' with message: Package 'Newtonsoft.Json' 12.0.3 has a known high severity vulnerability, https://github.com/advisories/GHSA-5crp-9r3c-p9vr
```

**Actual Behavior**:

The warning is reported as a failure:

```
Failure: Msbuild failed when processing the file 'C:\src\tmp\roslynworkspaceapp\project\project.csproj' with message: Package 'Newtonsoft.Json' 12.0.3 has a known high severity vulnerability, https://github.com/advisories/GHSA-5crp-9r3c-p9vr
```

The problem is in `Microsoft.CodeAnalysis.MSBuild.DiagnosticReporter`, whose `Report(DiagnosticLog log)` method ignores `DiagnosticLogItem.Kind`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.