NuGet packages can contain
multiple dlls each targeting a different framework version
. This is useful for libraries that want to both make use of the latest framework classes and also provide a paired down experience for older framework consumers.
is one example of a package that contains binaries for multiple frameworks.
I am presently developing my own library to be published with NuGet. I also want to target multiple frameworks, and have structured my nupkg to have net40 and net45 subdirectories of lib. To automate this, I have a build configuration for each target framework.
I can make net45 my default configuration, and switch over to net40 to build a lesser version of my library for that framework. After a couple of passes with MSBuild, I have binaries that target different frameworks and I can easily pack those in the appropriate
My question concerns bringing in dependencies that also target multiple frameworks. Say I want my library to depend on Json.net. From my Visual Studio solution, I can easily find the Json.net package in the package manger. NuGet downloads the package, extracts
it, and mutates my csproj file to add a reference to the dll. Obviously, the HintPath for this reference is going to refer the Json.net dll in its net45 folder because my selected configuration at the time was net45. Building in that net45 configuration is
fine, but when I switch to my net40 configuration, I'm going to have problems because that hint path is causing me to compile against the Json.net library for net45.
I can easily solve this problem by editing my csproj file to use MSBuild property shenanigans to devise the right HintPath depending on the current configuration. However, these modifications would get blown away whenever I use NuGet to update the Json.net
package. Since I am working with a team of people, I want to have something a bit more robust that doesn't require policing them on how to update a NuGet reference. Ideally, NuGet would understand my MSBuild customizations, but that's probably too much to
hope for. How do other developers of multi-framework libraries handle this issue?