在Visual Studio 2012中,c++ CLR支持的DLL项目中,将。net framework 4.5降至4级?

时间:2022-09-01 18:28:45

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.

当我在。net framework 4.5中添加了一个c++ CLR DLL的引用时,我在链接Visual c# . net framework 4.0支持的项目时遇到了这个错误。

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?

因此,对于这个c++ CLR支持的DLL项目,我如何在Visual Studio 2012中将。net framework 4.5降至4.0 ?

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

我以前见过,这就是原因。对于我的c++,这个链接可以帮助我的原因: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?

有人见过吗?那么我是如何降级c++ DLL的呢?

Thanks

谢谢

3 个解决方案

#1


11  

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:

c++ IDE不支持。net项目的多目标。您需要手工编辑.vcxproj。如果打开项目,请关闭它,并在文本编辑器中打开.vcxproj。找到这条线:

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

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

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.

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

#2


2  

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

http://msdn.microsoft.com/en-us/library/bb772098(v =应用程序). aspx

#3


0  

what worked for me was: in the project properties -> configuration properties -> project defaults. .NET Target framework version - edit to the version you need - in my case 4.6.1

对我起作用的是:在项目属性—>配置属性—>项目默认值。net目标框架版本—编辑到您需要的版本—在我的案例4.6.1中

#1


11  

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:

c++ IDE不支持。net项目的多目标。您需要手工编辑.vcxproj。如果打开项目,请关闭它,并在文本编辑器中打开.vcxproj。找到这条线:

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

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

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.

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

#2


2  

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

http://msdn.microsoft.com/en-us/library/bb772098(v =应用程序). aspx

#3


0  

what worked for me was: in the project properties -> configuration properties -> project defaults. .NET Target framework version - edit to the version you need - in my case 4.6.1

对我起作用的是:在项目属性—>配置属性—>项目默认值。net目标框架版本—编辑到您需要的版本—在我的案例4.6.1中