Roslyn: CS1998 is not suppressed by SuppressMessage when building with MSBuild.exe

Created on 12 Jul 2018  路  7Comments  路  Source: dotnet/roslyn

Version Used:
MSBuild from VS2017 15.7.5

Steps to Reproduce:
We see this on our build server and I've reproduced it locally.

Using the SuppressMessageAttribute successfully suppresses the warning in Visual Studio, but when rebuilding using MSBuild the warning is still reported in the console output.
[SuppressMessage("Compiler", "CS1998")] public async Task Foo() { }

Still gives the warning:

Program.cs(16,27): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider usi ng the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [D:\temp\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj]

  1. Run &"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0Bin\MSBuild.exe" .\
    ConsoleApp1.sln /t:rebuild
  2. Observe console output.

Expected Behavior:
CS1998 is suppressed when building with MSBuild.exe

Actual Behavior:
CS1998 is not suppressed when building with MSBuild.exe

Example solution that reproduces it:
ConsoleApp1.zip

Area-Compilers Resolution-Duplicate

All 7 comments

This behavior is "By Design". The SuppressMessageAttribute does not control compiler warnings but rather other diagnostic sources.

@jaredpar What would the recommended way be to suppress warnings in this scenario?

@PeteBoyRocket you can do one of the following:

  • Use a #pragma warning disable 1998 in the specific method
  • Disable the warning globally via /nowarn

So we should favour #pragma over SuppressMessage in general too? As suppressing the message locally is irrelevant if our CI system will always detect it

@jaredpar We couldn't find this information on the docs. Is there somewhere or does it need amending?

This behavior is "By Design".

Please change the design. Pragmas are disgusting.
Please see my comment here as well.

Duplicate of #6471

Was this page helpful?
0 / 5 - 0 ratings