我是Visual Studio 2010项目配置的新手,但我做了一些研究,仍然不能完全解决这个问题。我有一个Visual Studio解决方案的c++ DLL引用c# DLL。c# DLL引用了一些其他DLL,一些在我的项目内,一些在外部。当我试图编译c++ DLL时,我得到这个警告:

警告MSB3270:正在构建的“MSIL”项目的处理器架构与参考“[内部c# dll]”,“x86”的处理器架构之间不匹配。

它告诉我去配置管理器调整我的架构。c# DLL是用目标平台x86建立的。如果我尝试将其更改为其他东西,如任何CPU,它会抱怨,因为它所依赖的外部dll之一具有平台目标x86。

当我查看配置管理器时,它显示了我的c# DLL作为x86和我的c++项目作为Win32的平台。这似乎是正确的设置;当然,我不希望我的c++项目的项目平台设置为x64,这是唯一的其他选项。

我哪里做错了?


当前回答

对于MS Fakes程序集,您也可能会收到此警告,因为f.s csproj是基于命令构建的,因此不容易解决。幸运的是,Fakes xml允许您在其中添加它。

其他回答

我以前遇到过类似的问题,特别是在向现有的x64解决方案(如SharePoint)添加测试解决方案时。在我的例子中,这似乎与默认情况下某些项目模板被添加为某些平台有关。

Here's the solution that often works for me: set everything to the correct platform in the Configuration Manager (the active configuration drop-down, says Debug normally, is a good way to get to it) and project platform (in project properties), then build, then set everything back to AnyCPU. Sometimes I have to remove and re-add some dependencies (DLLs in each project's Properties) and sometimes the "Run tests in 32 bit or 64 bit process" (double-click Local.testsettings and go to Hosts) has to be changed.

在我看来,这只是设定了一些事情,然后又把它放回去,但在幕后可能有更多我没有看到的事情发生。不过在过去,这对我来说是相当稳定的。

我得到的警告和我做的一样

卸载项目 编辑项目属性,即。csproj 添加以下标签: < PropertyGroup > < ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch > 没有一个 < / ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch > < / PropertyGroup > 重新加载项目

我有类似的问题,这是由MS单元测试DLL引起的。我的WPF应用程序被编译为x86,但单元测试DLL(引用的EXE文件)为“任何CPU”。我将单元测试DLL更改为为x86编译(与EXE相同),并且它被解析。

我今天遇到了这个问题,只是在Visual Studio中查看建筑配置并没有帮助,因为它显示了没有建造的项目和引用项目的任何CPU。

然后我在参考项目的csproj中找到了这个:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>

不知怎么的,这个PlatformTarget是在配置更改的过程中添加的,而IDE似乎没有看到它。

从引用的项目中删除这一行解决了我的问题。

我在Visual Studio 2012编译SQL Server 2012 SP1 SSIS管道脚本任务时得到了这个警告-直到我安装了SQL Server 2012 SP2。