I have a class library (called ProjectA) that targets 4.5. It does not necessarily use 4.5 specific functionality. I need it to build 4.0 and 4.5 assemblies. I need it to produce a single NuGet package that has both assembly versions (4.0 + 4.5). It will be consumed by another class library (ProjectB) that also targets 4.5.
I also need ProjectB to do the same thing (build output assemblies for both 4.0 and 4.5) and create a single NuGet package that supports both.
I've added additional build configurations for 4.0 to both ProjectA and ProjectB projects:
In ProjectB, I've also added the additional dependency and files to the .nuspec file that is used to define dependecy on the NuGet from ProjectA:
ProjectA builds just fine and produces a NuGet .nupkg that has both binaries (one for 4.0 and one for 4.5). When ProjectB consumes ProjectA, it brings in the 4.5 assembly from ProjectA. When ProjectB compiles the 4.5 version of it's own assembly, everything is fine.
Here's where things get tricky. When I switch ProjectB to use it's 4.0 build configuration, Visual Studio will come up telling me that my reference to ProjectA is 4.5, and cannot be built with ProjectB's build configuration of 4.0.
I want Visual Studio to automatically use the 4.0 assembly from ProjectA, when the build configuration has been changed in ProjectB to 4.0.
I cannot downgrade 4.5 to 4.0 to make everything more seamless. Eventually, a ProjectC will consume both libraries 4.0 assemblies. Because ProjectC targets 4.0 and cannot be changed.
How do I get ProjectB to consume ProjectA, so that ProjectB will use the right assembly (4.0/4.5) from ProjectA, depending on which build configuration ProjectB is using.