Dependencies in a multi-framework build

Topics: Ecosystem
Sep 12, 2014 at 3:24 PM
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 nupkg structure.

My question concerns bringing in dependencies that also target multiple frameworks. Say I want my library to depend on From my Visual Studio solution, I can easily find the 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 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 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 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?