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]
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
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:
#pragma warning disable 1998
in the specific method /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