skip to Main Content

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


  1. You can turn off specific warnings for specific framework targets in multi-targeted projects by adding a conditional property group such as:

    <PropertyGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
      <NoWarn>IDE0090</NoWarn>
    </PropertyGroup>
    

    This will turn off the IDE0090 warning for the net7.0 build.

    It’s not ideal, but does mean that you don’t need to change the source code.

    Login or Signup to reply.
  2. I can manually set the language version or ignore the message code, but these are not viable long-term solutions

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search