Compile .NET libs for multiple target frameworks

BEN ABT
medialesson
Published in
2 min readDec 17, 2023

By default, the .NET and Visual Studio templates for .NET only provide one target framework as a target for the compiler; however, lib developers in particular often want to provide corresponding libraries for several .NET versions at the same time.

One of the ways is to simply choose the smallest .NET version in order to support as many targets as possible through upward compatibility.

If you then look at the NuGet overview of the package, this is shown accordingly.

Multiple Target Frameworks

What is not obvious at first glance from the Visual Studio project configuration: there is not only the option “TargetFramework” but also the plural “TargetFrameworks”.

And “TargetFrameworks” supports a semicolon-separated list of .NET targets.

If you now look at the NuGet overview of the package, this is shown accordingly: both .NET Frameworks are listed as ‘compatible target framework’

A small setting with a big impact.

--

--