Reputation: 1712
I'm trying to migrate my .NET 2.0 C++/CLI project from VS2008 to VS2012. After the conversion, the project depends on 4.0. When I do the
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
the project depends on 2.0 and 4.0. I verify that by looking in the External Dependencies magic folder in Solution Explorer. It also gives me compiler warning when I reference the project in a 2.0 C# project.
Commenting out #includes reveals that the 4.0 dependency is pulled in by #using directives in Microsoft headers such as vcclr.h and atlbase.h.
I need these headers for the classes and functions they provide. How do I make the #using directives in them point to 2.0 version of mscorlib.dll instead of 4.0?
Upvotes: 3
Views: 4946
Reputation: 941455
Changing the <TargetFrameworkVersion>
isn't enough, the build tools still use the .NET 4 version that's installed on your machine. Something you can see by running ildasm.exe on the generated assembly. Double click the manifest to see:
// Metadata version: v4.0.30319
...
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.hash = (DD 9E C9 8D BF 2A 2D C2 AA 2D C3 8B 51 CD 4C A6 // .....*-..-..Q.L.
15 F0 22 F6 ) // ..".
.ver 2:0:0:0
}
...
.assembly extern mscorlib as mscorlib_4
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.hash = (47 6E C0 E3 BA CD CE B1 9A 4D 68 BE 29 75 61 6F // Gn.......Mh.)uao
BE 04 C6 BA )
.ver 4:0:0:0
}
Note how both versions of mscorlib.dll ended up as a dependency. The problem you encountered.
The feedback article I linked recommended changing the toolset to "v90". This however doesn't work on my machine, even though I have VS2008 installed. The option doesn't show up in the combobox dropdown and when I force it I get this build error:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets(43,5): error MSB8020: The builds tools for Visual Studio 2008 (Platform Toolset = 'v90') cannot be found. To build using the v90 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install Visual Studio 2008 to build using the Visual Studio 2008 build tools.
Following the advice given in the error message, I get this:
------ Update VC++ projects started -------
Updating project 'ConsoleApplication74'...
Configuration 'Debug|Win32': changing Platform Toolset to 'v110' (was 'v90').
Configuration 'Release|Win32': no update required. Platform Toolset is 'v110'.
TargetFrameworkVersion = v4.5 (was v2.0)
Back to square one. I'd say that targeting .NET 2.0 in C++/CLI projects with VS2012 is a lost cause.
Upvotes: 4
Reputation: 17444
One way to do it is to open up the project file (.vcxproj) and change the
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
to
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
See Change C++/CLI project to another framework than 4.0 with vs2010
Upvotes: 1