6

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)"?

InteXX
  • 6,135
  • 6
  • 43
  • 80
amalgamate
  • 2,200
  • 5
  • 22
  • 44

2 Answers2

4

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

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • But then what am I doing wrong? Wait that is not a fair question. My copy of vs is fully licensed. I changed the project setting and ultimately one library or another that is set up to build 4.0 builds 4.5 instead.... Perhaps the question is not what am I doing wrong, but how can I find out what I am doing wrong: Is it possible that I can find out more about my problem by reviewing the settings file(s) or something? Should I frame a new question for my new question? and finally... How did you know that I have a fully licensed copy of VS? – amalgamate Aug 28 '14 at 19:51
  • The error message is rather unequivocal, blablaLibraryproject was built to target 4.5. You'll have to change that to 4.0. That's all you showed me. What didn't you tell me? – Hans Passant Aug 28 '14 at 19:55
  • That I set the project to 4.0 for all projects within the solution built the solution, got the error, and double checked the settings and they all said they were building 4.0. Sorry, I thought I said that but I seem to have missed that in my question, now that I look back. – amalgamate Aug 28 '14 at 20:12
  • Look at blablaLibraryproject.dll with ildasm.exe. Double-click the manifest to look at the TargetFrameworkAttribute value. Document what you see. – Hans Passant Aug 28 '14 at 20:16
  • Well there's a solution for you, I was unable to reproduce the problem... I am going to be working on it in the next few weeks. If I can reproduce the problem I will check as you have suggested. (I set the projects all to 4.5 and then set them back and the problem went away.) – amalgamate Aug 28 '14 at 20:34
0

In addition to Hans' answer, here is another possible reason for this:

My build server had Visual Studio installed, however, my project targeted .NET 4.0.3 and that specific target framework was missing on my build server. Therefore it silently defaulted to .NET 4.5.

I fixed this by changing the target framework of my project to .NET 4.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443