MSB3270:处理器架构不匹配 - Fakes框架

29

由于我在UnitTest中使用Fakes Framework,因此我遇到了以下MSBuild警告:

  

warning MSB3270:正在构建的项目的处理器架构“MSIL”与引用“DocumentServiceModel”的处理器架构“x86”不匹配。 这种不匹配可能导致运行时错误。 请通过“配置管理器”考虑更改项目的目标处理器架构,以使项目和引用之间的处理器架构对齐,或者对与项目的目标处理器架构匹配的处理器架构具有依赖关系的引用。 [C:\ Projekte \ XXX \ XXX \ XXX \ Source \ Testing \ UT \ XXX.UnitTest \ obj \ Debug \ Fakes \ ppsm \ f.csproj]

解决此构建警告的方法是什么?

更新1:

我认为问题在于Fakes Framework创建了一个带有平台目标“Any CPU”的动态项目。

  

(C:\ Projekte \ XXX \ XXX \ XXX \ Source \ Testing \ UT \ XXX.UnitTest \ obj \ Debug \ Fakes \ ppsm \ f.csproj)

该动态项目引用了我的项目中运行的具有平台目标“x86”的程序集。

我不知道如何将动态Fakes项目更改为“x86”。

更新2:

我创建了一个示例项目,结果遇到了相同的警告:

Warning 1   There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "MSBErrorTest", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. [C:\Projekte\MSBErrorTest\UnitTestProject1\obj\Debug\Fakes\msbet\f.csproj] UnitTestProject1

单元测试 csproj 文件:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProjectGuid>{4B14EC56-DDC7-4A16-92BA-2D2881E695D1}</ProjectGuid>
        <OutputType>Library</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <RootNamespace>UnitTestProject1</RootNamespace>
        <AssemblyName>UnitTestProject1</AssemblyName>
        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>
        <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
        <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
        <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
        <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
        <IsCodedUITest>False</IsCodedUITest>
        <TestProjectType>UnitTest</TestProjectType>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <DebugSymbols>true</DebugSymbols>
        <DebugType>full</DebugType>
        <Optimize>false</Optimize>
        <OutputPath>bin\Debug\</OutputPath>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <PlatformTarget>x86</PlatformTarget>
      </PropertyGroup>
      <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>x86</PlatformTarget>
      </PropertyGroup>
      <ItemGroup>
        <Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
        <Reference Include="MSBErrorTest.Fakes">
          <HintPath>FakesAssemblies\MSBErrorTest.Fakes.dll</HintPath>
        </Reference>
        <Reference Include="System" />
      </ItemGroup>
      <Choose>
        <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
          <ItemGroup>
            <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
          </ItemGroup>
        </When>
        <Otherwise>
          <ItemGroup>
            <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
          </ItemGroup>
        </Otherwise>
      </Choose>
      <ItemGroup>
        <Compile Include="UnitTest1.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
      </ItemGroup>
      <ItemGroup>
        <ProjectReference Include="..\MSBErrorTest\MSBErrorTest.csproj">
          <Project>{f1ae6c89-6f6a-404e-b9e2-10ee2f66942f}</Project>
          <Name>MSBErrorTest</Name>
        </ProjectReference>
      </ItemGroup>
      <ItemGroup>
        <Fakes Include="Fakes\MSBErrorTest.fakes" />
      </ItemGroup>
      <Choose>
        <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
          <ItemGroup>
            <Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
              <Private>False</Private>
            </Reference>
            <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
              <Private>False</Private>
            </Reference>
            <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
              <Private>False</Private>
            </Reference>
            <Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
              <Private>False</Private>
            </Reference>
          </ItemGroup>
        </When>
      </Choose>
      <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
      <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
      <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
           Other similar extension points exist, see Microsoft.Common.targets.
      <Target Name="BeforeBuild">
      </Target>
      <Target Name="AfterBuild">
      </Target>
      -->
    </Project>

类库 csproj:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{F1AE6C89-6F6A-404E-B9E2-10EE2F66942F}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MSBErrorTest</RootNamespace>
    <AssemblyName>MSBErrorTest</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <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>x86</PlatformTarget>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

更新3:

我已将我的配置更改为以下内容。

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>

但我仍然收到警告


请查看我的更新答案,以强制目标平台使用x86。 - Eriawan Kusumawardhono
Visual C# - 单元测试项目 - .NET 4.5 - Snowcrack
你是否已经更新了你的VS 2012并安装了Update 3? - Eriawan Kusumawardhono
是的,我们使用的是VS2012高级版更新3。 - Snowcrack
是的,我已经两个都改了。 - Snowcrack
显示剩余7条评论
5个回答

11

太棒了...我遇到了同样的问题,通常的答案是更改解决方案/项目设置。Fakes设置解决了问题。非常感谢。 - Carbine
当我使用它时,我将这个答案中的文本放在我的伪造文件顶部,就在伪造部分内,然后它抱怨说它期望一个程序集条目。我将其移动到文件底部,一切都很好。感谢您的答案,我已经为此奋斗了很长时间。 - David Parvin

6

由于我只在 Fakes 组件上运行单元测试时才会遇到此错误,因此我决定忽略此错误。您可以通过将以下内容添加到您的 Fakes XML 文件中来实现这一点:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="FakedAssemblyName.dll"/>
  <Compilation>
    <Property Name="ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch">None</Property>
  </Compilation>
</Fakes>

4

您是否使用第三方库?如果使用了,请检查它们是否使用与目标处理器相同的x86。 显然,所有引用的目标处理器都应该相同,而不仅仅是您项目的目标。

更新:显然,微软的这个人也遇到了这个问题。您可以尝试使用他的解决方法:

http://blogs.msdn.com/b/astebner/archive/2012/05/03/10300809.aspx

从博客文章中,按照以下步骤操作: 在您的csproj文件中搜索“PlatformTarget”,并将其编辑为以下内容:

<PlatformTarget Condition=" '$(PlatformTarget)' == '' ">x86</PlatformTarget>

请告诉我这是否解决了你的问题。

更新2:根据您提供的unittest.csproj和classlib.csproj源代码,配置仍然基于“AnyCPU”。

请查找此行:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">

还有这一行:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

那些目标平台也应该设置为使用x86。
更简单的方法是通过在Visual Studio工具栏上点击“Debug”组合框中的“Configuration Manager…”来设置Debug和Release,就像这个粗略的示例中所示:

Visual Studio 2012 Debug/Release


是的,我们使用第三方库。但它们似乎都没问题。只有当我使用 Fakes Framework 时才会出现问题。没有使用 Fakes Framework 时一切正常! - Snowcrack
1
Fake Framework 要求您针对所有引用使用 x86。您是否检查了第三方库的目标? - Eriawan Kusumawardhono
我刚刚删除了一个项目的所有第三方库,但警告仍然存在。 - Snowcrack
你正在使用VS 2012 Beta或Preview吗?如果是的话,请尝试重新安装VS 2012 RTM。 - Eriawan Kusumawardhono
我们正在使用VS2012 Premium Update 3。 - Snowcrack
显示剩余3条评论

0

对于任何来到这里与“伪造”无关的人,请检查您的引用中是否有警告/错误。我发现了一个幽灵 DLL,幸运的是该项目不需要它,因此将其删除。效果很好!


0
project_name.csproj 文件中删除设置了 processorArchitecture 属性的 ItemGroup 节点。它看起来像这样; <ItemGroup> <Reference ... , processorArchitecture=MSIL"> ... </ItemGroup> 这对我很有帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接