Jaime
Jaime

Reputation: 5975

Duplicate error messages in .NET Core - error CS0116

Steps to reproduce

dotnet new console
(introduce a bug in Program.cs)
dotnet restore
dotnet build

The typical output would be:

Microsoft (R) Build Engine version 15.1.548.43366 Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]

Build FAILED.

Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.77

You can see the error CS0116 is reported twice.

Is there a way to avoid the duplication in the reporting of errors?

Upvotes: 4

Views: 1426

Answers (2)

TerribleDev
TerribleDev

Reputation: 2245

You can make your own MSBuild logger, instead of using the default console logger. There are really good instructions in Build loggers.

Essentially, you could make your own logger that captured all the data, and then emitted a simple summary at the end.

dotnet build /noconsolelogger /logger:YourCustomLogger.dll

Upvotes: 0

Martin Ullrich
Martin Ullrich

Reputation: 100751

The second error is part of the console logger's summary. This can be disabled by passing in /clp:NoSummary to msbuild. However, there is currently a bug in the CLI when it is the first MSBuild argument to dotnet build. Add any other MSBuild command before it to make it work. Since you want to reduce the verbosity, let's just use /nologo for the workaround:

dotnet build -c Release /nologo /clp:NoSummary

However, it works great if you use MSBuild directly:

dotnet msbuild /clp:NoSummary /p:Configuration=Release

In the upcoming 2.0.0 release, the CLI always overrides the summary parameter for dotnet build, so you'll have to use dotnet msbuild instead (I opened an issue on GitHub on that).

Upvotes: 11

Related Questions