Today, I wanted to make sure that the dll targets multiple versions of the framework.

But before the SDSDK style SD cspro project, you had to make a cspro file per target framework which was long and tedious.

Now with the new csproj format we have a new property called TargetFrameworks which allows us to generate our dll in different dll formats with a single csproj.

If I want my dll to be compiled into .NET Standard 2.0 and I also want to support .NET Standard 1.3, I just need to replace the following line:


<TargetFramework>netstandard1.3</TargetFramework>

By:


<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>

The output directory now has two directories:

Original illustration unavailable

Note: You can find the list of values accepted by the TargetFrameworks node here

Add a NuGet package for a specific version

In my case, if I target standard .NET 1.3 I want to add a reference to the NuGet of System.Xml.XmlSerializer because the XmlSerialization class only arrived in .NET Standard 2.0.

Add the NuGet package only when’Netstandard 1.3 is targeted:

To be able to add a NuGet package only when I'm in .NET Standard 1.3 I'm going to check that the variable TargetFramework is equal to netstandard1.3.


<ItemGroup Condition=" $(TargetFramework) =='netstandard1.3')">
    <PackageReference Include="System.Xml.XmlSerializer" Version=" 4.3.0/>
</ItemGroup/>

The solution explorer allows us to check at a glance that our configuration is well taken into account. System.Xml.XmlSerializer is only added for configuration netstandard1.3.

Original illustration unavailable

Happy coding.