Asik
Asik

Reputation: 22123

Is Platform Toolset v110 incompatible with .NET 3.5?

This is with Visual Studio 2012 Ultimate Update 3.

I have a C# project that targets .NET 3.5. This project uses a C++/CLI dll which is also compiled for .NET 3.5.

I have noticed that if the C++ dll is compiled with Platform Toolset v110, then although I can add it to the C# project, and see the types in Intellisense, the compiler itself doesn't see any of the types. It complains that they do not exist and that I am missing an assembly reference. This does not happen if it is compiled with Platform Toolset v90.

If I then re-target the C# project to .NET 4 or 4.5, then it sees the types alright. The types do exist in the assembly and can be seen in the object explorer or Ildasm.

It therefore seems that the use of Platform Toolset v110 makes it impossible to use the dll from a .NET 3.5 project, even though the dll is compiled for .NET 3.5.

Is this normal and/or documented behavior? Is there any way around this other than either downgrading the C++/CLI project to Platform Toolset v90 or upgrading the C# project to .NET 4?

Upvotes: 0

Views: 1533

Answers (1)

Sheng Jiang 蒋晟
Sheng Jiang 蒋晟

Reputation: 15281

As always Toolset v110 does not support any .Net version other than 4.5. Officially, to change the target framework you must change the platform toolset to a version that supports the target .Net version (e.g. Windows 7 SDK for .net 2.0-3.5 SP1). This involves changing TargetFrameworkVersion in the project file as well as switching to another platform toolset.

That said, the toolset is just a bunch of msbuild rules so you may get the the compiler to retarget the .Net version by changing the vcxproj and global msbuild rules in project file. Olga Arkhipova from the VC++ team comes up with this:

<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<RealTargetFrameworkVersion>$(TargetFrameworkVersion)
</RealTargetFrameworkVersion>

Add a file to 'C:\Program Files (x86)\MSBuild\4.0\Microsoft.Common.Targets\ImportBefore

<Project ToolsVersion="4.0" 
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
    <TargetFrameworkVersion 
         Condition="'$(RealTargetFrameworkVersion)' != ''">
         $(RealTargetFrameworkVersion)
    </TargetFrameworkVersion>
</PropertyGroup>
</Project>

Upvotes: 2

Related Questions