在Visual Studio 2012 for C ++ CLR支持的DLL项目中降级.NET框架4.5到4? [英] Downgrade .NET framework 4.5 to 4 in Visual Studio 2012 for C++ CLR supported DLL project?

查看:1087
本文介绍了在Visual Studio 2012 for C ++ CLR支持的DLL项目中降级.NET框架4.5到4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在4.5 .NET Framework中添加了C ++ CLR DLL的引用时,链接Visual C#.NET framework 4.0支持的项目时出现此错误。

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

因此,如何在Visual Studio 2012中将.NET framework 4.5降级到4.0这个C ++ CLR支持的DLL项目?

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?

我看到这之前是原因。对于我的C ++,此链接可能有助于我的原因 http:// msdn。 microsoft.com/en-us/library/bb772098(v=vs.90).aspx

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". 

以前看过这个吗?那么如何降级C ++ DLL?

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

感谢

推荐答案

C ++ IDE不支持.NET项目的多目标定位。您需要手动编辑.vcxproj。如果项目已打开,请关闭项目,并在文本编辑器中打开.vcxproj。找到此行:

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>

并将其修改为v4.0。在VS中再次打开项目。项目+属性,公共属性,框架和参考。在列表中选择系统并检查相对路径属性。现在应该指向4.0版本。

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.

小心一个重要问题,以及C ++ IDE不支持多重定位的核心原因。 #using指令有问题,它从c:\windows \microsoft.net子目录加载程序集。这将得到它加载一个.NET 4.5程序集,而不是你想要的目标4.0时的4.0程序集。 4.0引用程序集存储在c:\program files\参考程序集中。这可能会导致非常难以诊断运行时问题,4.5程序集与4.0程序集不兼容。这是很容易避免#using在自己的代码,但它用于include / msclr / marshal.h和include / vcclr.h头文件。如果您使用这些标头,请注意。

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.

这篇关于在Visual Studio 2012 for C ++ CLR支持的DLL项目中降级.NET框架4.5到4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆