I’m working with a solution containing over 50 projects targeting both .NET Framework 4.8 and .NET 7 (Windows only). I’ve encountered an issue where the compiler provides syntax suggestions that are incompatible with C# 7.3, such as IDE0090, which requires C# 9 or higher. Implementing these suggestions causes the build to fail for .NET 4.8 targets.
To resolve this, I can manually set the language version or ignore the message code, but these are not viable long-term solutions since we plan to eventually move away from .NET 4.8 and I don’t want to lock in a specific language version.
Is there a setting or feature in Visual Studio 2022 that can manage language version detection more accurately? It seems problematic that the compiler fills the Errors List with tons of recommendations based on the maximum language version rather than the minimum required.
2
Answers
You can turn off specific warnings for specific framework targets in multi-targeted projects by adding a conditional property group such as:
This will turn off the
IDE0090
warning for thenet7.0
build.It’s not ideal, but does mean that you don’t need to change the source code.
Use
<LangVersion>preview</LangVersion>
, it will allow every supported C# version to be used, regardless of whether you’re using .Net Core or .Net Framework. Most syntax-level features are on the compiler side, not on the runtime side.