Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downgrade .NET framework 4.5 to 4 in Visual Studio 2012 for C++ CLR supported DLL project?

I get this error when linking a Visual C# .NET framework 4.0 supported project as I added a reference of C++ CLR DLL with 4.5 .NET Framework.

error CS0246: The type or namespace name 'project' could not be found (are you missing a using directive or an assembly reference?)

As a result, how do I downgrade .NET framework 4.5 to 4.0 in Visual Studio 2012 for this C++ CLR supported DLL project?

I have seen this before which was the cause. For my C++, this link may help out my cause http://msdn.microsoft.com/en-us/library/bb772098(v=vs.90).aspx

I just discovered this warning as well:

 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3274: The primary reference "X" 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". 

Anyone seen this before? So how I downgrade the C++ DLL?

Thanks

like image 361
heavy rocker dude Avatar asked Feb 08 '13 06:02

heavy rocker dude


People also ask

How do I downgrade .NET Framework?

According to this Microsoft blogpost the only way to downgrade is to uninstall the current version and (after that) install the older version.


2 Answers

The C++ IDE doesn't support multi-targeting for .NET projects. You'll need to edit the .vcxproj by hand. Close the project if you have it open and open the .vcxproj in a text editor. Locate this line:

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

and modify it to "v4.0". Open the project again in VS. Project + Properties, Common Properties, Framework and References. Select "System" in the list and check the Relative Path property. It should now point to the 4.0 version.

Do beware of a significant issue and the core reason that the C++ IDE does not support multi-targeting. There is a problem with the #using directive, it loads assemblies from the c:\windows\microsoft.net subdirectory. Which will get it to load a .NET 4.5 assembly instead of the 4.0 assembly that you want when you target 4.0. The 4.0 reference assemblies are stored in c:\program files\reference assemblies. This can cause very hard to diagnose runtime problems, the 4.5 assemblies are not that compatible with the 4.0 assemblies. It is easy enough to avoid #using in your own code but it used in the include/msclr/marshal.h and include/vcclr.h header files. Caveat emptor if you use these headers.

like image 185
Hans Passant Avatar answered Oct 21 '22 07:10

Hans Passant


I have figured it out. It was the warning but the link specified did fix the problem.

http://msdn.microsoft.com/en-us/library/bb772098(v=vs.90).aspx

like image 32
heavy rocker dude Avatar answered Oct 21 '22 09:10

heavy rocker dude