I’m trying to author a family of class libraries which are used between multiple applications within the organization. Some of those applications target .NET 3.5 and some target 4.0.
We want to provide two versions of the assemblies, one targeting 3.5 and one targeting 4.0, so that the host applications can select whichever assembly is most appropriate for them.
There are some subtle differences between the 3.5 and 4.0 versions:
- Some classes have been removed due to being superseded by .NET 4.0 versions.
- Some classes have been added to assist working with classes introduced by .NET 4.0.
- Some classes have been modified in the 4.0 version to take advantage of some of the enhanced threading support in 4.0.
Is there any solution that will allow me to re-use the overlapping portions of the code-base and prevent simply forking the source tree?
My objective is to produce multiple versions of the assemblies targeting their specified frameworks which can be rolled into a NuGet package and exposed on our internal feed.
If you’re planning on writing a family of class libraries that will support multiple .NET frameworks (and/or platforms), you may want to create a “Portable Class Library”.
Full details are in the blog post Targeting Multiple Platforms with Portable Code (Overview). In Visual Studio 2012, you simply create a new “Portable Class Library” project, whereas in Visual Studio 2010 you’ll need to install the Portable Library Tools first.
With a PCL project, you can target the following platforms:
However, note that .NET Framework 3.5 is not currently included in this list. The Portable Library Tools were written so that other platforms can be added in the future, with Mono support currently at the top of the list.