问题描述
我是 Visual Studio 2010 项目配置的新手,但我已经完成了一些 研究 仍然无法弄清楚这个问题.我有一个带有引用 C# DLL 的 C++ DLL 的 Visual Studio 解决方案.C# DLL 引用了一些其他 DLL,一些在我的项目中,一些在外部.当我尝试编译 C++ DLL 时,收到此警告:
I'm new to project configuration in Visual Studio 2010, but I've done some research and still can't quite figure this issue out. I have a Visual Studio solution with a C++ DLL referencing the C# DLL. The C# DLL references a few other DLLs, some within my project and some external. When I try to compile the C++ DLL, I get this warning:
警告 MSB3270:正在构建MSIL"的项目的处理器架构与参考[内部 C# dll]"、x86"的处理器架构之间存在不匹配.
它告诉我去配置管理器来调整我的架构.C# DLL 设置为平台目标 x86.如果我尝试将其更改为其他内容,例如 Any CPU,它会抱怨,因为其中一个外部 DLL it 依赖于平台目标 x86.
It tells me to go to Configuration Manager to align my architectures. The C# DLL is set up with platform target x86. If I try to change this to something else, like Any CPU, it complains because one of the external DLLs it depends on has platform target x86.
当我查看配置管理器时,它显示我的 C# DLL 的平台为 x86,而我的 C++ 项目的平台为 Win32.这似乎是正确的设置;当然,我不希望我的 C++ 项目的平台设置为 x64,这是提供的唯一其他选项.
When I look at Configuration Manager it shows the Platform for my C# DLL as x86 and for my C++ project as Win32. This seems like the right setup; surely I don't want the project for my C++ project to have platform set to x64, which is the only other option presented.
我在这里做错了什么?
推荐答案
这个警告似乎是在新的 Visual Studio 11 Beta 和 .NET 4.5 中引入的,尽管我认为它以前可能是可能的.
This warning seems to have been introduced with the new Visual Studio 11 Beta and .NET 4.5, although I suppose it might have been possible before.
首先,这真的只是一个警告.如果您只是处理 x86 依赖项,它应该不会有任何伤害.当您声明您的项目与任何 CPU"兼容但您依赖于 x86 或 x64 的项目或 .dll 程序集时,Microsoft 只是试图警告您.由于您有 x86 依赖项,因此从技术上讲,您的项目与任何 CPU"不兼容.为了使警告消失,您实际上应该将您的项目从任何 CPU"更改为x86".这很容易做到,以下是步骤.
First, it really is just a warning. It should not hurt anything if you are just dealing with x86 dependencies. Microsoft is just trying to warn you when you state that your project is compatible with "Any CPU" but you have a dependency on a project or .dll assembly that is either x86 or x64. Because you have an x86 dependency, technically your project is therefore not "Any CPU" compatible. To make the warning go away, you should actually change your project from "Any CPU" to "x86". This is very easy to do, here are the steps.
- 转到构建|配置管理器"菜单项.
- 在列表中找到您的项目,在平台下它会显示任何 CPU"
- 从下拉菜单中选择Any CPU"选项,然后选择
- 在该对话框中,从新平台"下拉菜单中选择 x86,并确保在复制设置自"下拉菜单中选择任何 CPU".
- 点击确定
- 您需要为调试和发布配置选择 x86.
这将使警告消失,并说明您的程序集或项目现在不再与任何 CPU"兼容,但现在特定于 x86.如果您正在构建具有 x64 依赖项的 64 位项目,这也适用;您只需选择 x64.
This will make the warning go away and also state that your assembly or project is now no longer "Any CPU" compatible but now x86 specific. This is also applicable if you are building a 64 bit project that has an x64 dependency; you would just select x64 instead.
另外一个注意事项,如果项目是纯 .NET 项目,它们通常可以与任何 CPU"兼容.只有当您引入针对特定处理器架构的依赖项(第 3 方 dll 或您自己的 C++ 托管项目)时,才会出现此问题.
One other note, projects can be "Any CPU" compatible usually if they are pure .NET projects. This issue only comes up if you introduce a dependency (3rd party dll or your own C++ managed project) that targets a specific processor architecture.
这篇关于如何修复 Visual Studio 编译错误“处理器体系结构不匹配"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!