0

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:

enter image description here

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:

enter image description here

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.

Steve Kennedy
  • 5,312
  • 3
  • 26
  • 41
  • 2
    You can try creating two different configurations, one for .net 4.0 and one for .net 4.5 and then use conditional references in csproj. Example: http://stackoverflow.com/questions/6523008/visual-studio-2010-conditional-references – MistyK Jan 27 '17 at 18:19
  • @Zbigniew Thank you. Your comment helped out tremendously. I had to figure out creating two different REFERENCES as well, which seemed to pan out. I upvoted your comment. If you submit this as an answer with more details (feel free to steal mine), I'd be glad to mark your answer. – Steve Kennedy Jan 27 '17 at 19:36
  • no problem, I'll mark your answer as an answer as it contains all the details. – MistyK Jan 27 '17 at 19:38

1 Answers1

1

After a few more hours of research, and having visited to my work peers (and a comment from @zbigiew), I was lead to determine that I needed to update the project file for ProjectB. Effectively, I had to let the project know which Reference to use based on a CONDITIONAL statement in the project file, for two different/separate references to ProjectA's binaries (4.0/4.5).

The section helps define which references are associated with the project. The itself can be made optional depending on a variety of conditions. In my case, I had to set the condition to say, if the build configuration is "Release40" use the 4.0 assembly from the . And another Reference saying, if the build configuration is "Release" use the 4.5 assembly from a different .

enter image description here

Steve Kennedy
  • 5,312
  • 3
  • 26
  • 41
  • glad to know that you have resolved this issue, thanks for your sharing. You could mark it as the answer:) – Jack Zhai Jan 30 '17 at 02:34