The issue comes up when you install Visual studio 2012 on a machine without Visual studio 2010 installed previously (I think). I want to target .net 4.0, while building on Visual Studio 2012. I already have set up the machine without VisualStudo 2010. I end up with messages like:
*Warning 2 The primary reference "blablaLibraryproject" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0". blablaExecutableproject*
The answering post here(Can a build server with .NET 4.5 installed successfully deploy a project targeting 4.0 to a server with only .NET 4.0 installed?) says:
You can correct this, but you need to add the 4.0 reference assemblies to your build server (so the compiler finds them), and not just rely on the .NET 4.5 versions.
So how does one "add the 4.0 reference assemblies to your build server (so the compiler finds them)"?
One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.
Navigate to the startup project in solution explorer. Right click, properties > Application > Target framework. Change the target framework to anything else. Press Yes for the confirmation dialog.
They are already present on the machine. Just change the Target Framework setting of the project from 4.5 to 4.0
The problem discussed in that linked question is a pretty common one for programmers that try to setup a build server without paying for the VS license. Which goes pretty far, but is missing an otherwise freely available component, the multi-targeting packs for the .NET Framework versions.
Which is penny-wise but pound-foolish. They then make a fatal mistake, they add reference assemblies from c:\windows\microsoft.net instead. Like it was done in framework versions prior to .NET 4.0. This causes horrible to diagnose runtime exceptions when the built product is ran on a machine that only has 4.0 installed. The asker of the question was pretty lucky, he got a relatively easy to diagnose one. That however can be a lot worse, getting pretty bizarre TypeLoadExceptions for common framework types.
You don't have this problem, you installed VS so you already got the multi-targeting packs. The 4.0 version is available in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0. Both MSBuild and VS know how to find it there without your help. Just change the project setting to tell them that you want to target 4.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With