Multi target frameworks for .NET libraries

Visual Studio

In order for a package or library to target multiple frameworks we should edit the .csproj file and change "TargetFramework" To "TargetFrameworks", then specify a comma separated list of supported frameworks.

When some framework requires a nuget package or a reference while other does not, we can conditionally reference it by editing the .csproj file like this example:


<PackageReference Include="System.Security.Cryptography.Pkcs" Version="7.0.0" Condition="'$(TargetFramework)' == 'net7.0'"/>

Post a Comment

Previous Post Next Post