We have a class library currently targeting .NET 4.6.2
which has some dependencies (SDK classes) that are resolved via nuget.
All the SDK-Assemblies required by that class library are available for multiple target platforms (eg. 4.6.2
, 4.5.2
etc.).
We are using VSTS to both build the library and pack/push it to a private NuGet feed.
Now, we need our Class-Library to both target .NET 4.5.2
as well as .NET 4.6.2
because we have a project using this library targeting .NET 4.5.2
(and no, unfortunately upgrading its target is no option)
So the acutal question is: Is there a way to build the solution for both multipe target-frameworks?
What I tried so far:
I also thought about some kind of script for parsing and manipulating all the packages.config
and *.csproj
files, but I guess this isn't best practice at all.
It's quite easy to have an assembly/class library that can be used by projects targeting different versions of the .Net Framework.
If you have projects targeting 4.5.2 and 4.6.2 but you want to provide a common library then have your library target 4.5.2. .Net makes is essentially backwards compatible so you can always use a library targeting a lower version than the version the consuming library/project targets. Technically you could target anything below that too including 3.5, but why would you.
This also applies to .Net Core and .Net Standard too but the combinations quickly stack up. If the library targets .Net Standard 1.0 then it can be consumed by projects targeting any version of .Net Standard >= 1.0, any version of .Net Core >= 1.0 and any version of .Net Framework >= 4.5.2. Take a look at the docs on .Net Standard for details.
For more details on .Net Standard check out this blog post from Daniel Crabtree