Multiple Frameworks Library

I recently forked a C# library project from GitHub and noticed that it targets more than one framework. Interesed in how to create such a project I googled a bit an found the way how to target more than one framework.

Creating the library

To create such a project just create a default library project within vs.

After creating the library you can see the targeting framework under “Dependencies” or the project settings.

To create a library that supports more frameworks close the project and open the “MultipleTargetLibrary.csproj” with a editor.
The file will look like:

Now change TargetFramework to TargetFrameworks and add the framework version you want to support

If you now go back and open the project you will see that under “Dependencies” all the desired frameworks will be listed.

If you now build the library vs will create a *.dll file for each framework.

That’s how to create a project that supports more than one target framework.

Extra

If you also want to create a nuget package from your library you have to take care that when you create the project the target framework will be .netstandard 2.0. Then vs will create a package tab inside your’e project. settings.

If you check the first checkbox (create nuget package when build project) vs will create anuget every time you build the library.

2 thoughts on “Multiple Frameworks Library

  1. Great idea, thanks for sharing ๐Ÿ™‚ I didn’t know until know, that this may be possible. Great job!

Leave a Reply

Your email address will not be published. Required fields are marked *