Search code examples
msbuildvisual-studio-code.net-coredotnet-cli

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?


Solution

  • 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).