VS IDE Suppress Compiler Warnings Project Wide
There are some cases where it is necessary to suppress IDE compiler warnings that apply to the entire project.
This can be warnings that occur several times across the source files.
Or, it can be for a compiler warning that the project’s framework target is out of support.
This latter case is currently a problem for any VS solution that is maintaining older framework targets, such as for NET5.0 which is out of support (as of 2022, I think).
Anyway. To suppress a compiler warning for an unsupported framework target, or to suppress many occurrences of the same error, edit your project file by adding a NoWarn entry to the PropertyGroup that lists the Target Framework.
For example, the following project file fragment suppresses compiler warnings for NET5 being out of support:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<!-- NoWarn below suppresses NETSDK1138 project-wide -->
<!-- This suppresses the IDE warning that NET5.0 is out of support. -->
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
...
<PropertyGroup>
...
</Project>
In the above example, the NoWarn entry suppresses compiler warning “NETSDK1138
“, project-wide.
See this reference for some warnings for obsolete features of NET5: Obsolete features in .NET 5+ - .NET
See this reference for the specific compiler warning that Net5 is out of support: NETSDK1138: The target framework is out of support - .NET CLI
No Comments