Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify .NET version when using /CLR option

I am compiling third party C++ code using /CLR flag which requires only .NET Framework 3.5.

The code is getting compiled fine, but since I have .NET 4.0 installed on my dev box the resulting binary doesn't work for any .NET framework less than 4.0

So, how do I tell Visual Studio to use a particular version of the .NET Framework while compiling?

like image 921
user837208 Avatar asked Oct 25 '11 20:10

user837208


1 Answers

Quoting an article on the Visual C++ Team Blog, Visual Studio 2010 C++ Project Upgrade Guide:

... the VS2010 compiler cannot target Framework 2.0, 3.0 or 3.5. The VS2008 compiler must be used to target 2.0, 3.0 or 3.5. ... The C++ applications can be retargeted to other frameworks (say 3.5 for example) by one of the following methods:

  • Edit the vcxproj file and in the first property group define add the following: <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  • Open the VS2010 command line, set TargetFrameworkVersion=v3.5, and then start devenv.exe from the commandline. This will target all your C++ applications to v3.5 framework.
  • Pass /p:TargetFrameworkVersion=v3.5 to MSBuild when building applications: MSBuild my.vcxproj /p:TargetFrameworkVersion=v3.5

Note that VS2008 has to be installed on the machine for the application to target 2.0, 3.0 or 3.5.

like image 146
ildjarn Avatar answered Nov 14 '22 02:11

ildjarn