c# - 警告 MSB3270 架构不匹配/AL1073 针对不同的处理器

标签 c# c++ visual-studio

我的项目具有本地化资源和 x64 native 依赖项。有没有办法在没有警告的情况下构建它们?

如果我将目标平台设置为 AnyCPU,我会因为 native 引用而收到此警告:

warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Native64", "AMD64". 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.

好吧,但是:

如果我将目标平台设置为 x64,我会收到此警告,因为本地化资源会自动创建一个目标架构错误的附属程序集:

ALINK : warning AL1073: Referenced assembly 'mscorlib.dll' targets a different processor

Microsoft说这是一个错误,但他们不会修复它。

那么现在呢?

最佳答案

解决办法:

可以通过使用与您尝试构建的平台(或位数)相匹配的 AL.EXE 来避免该问题。也就是说,当您构建 x64 时,您会看到它试图在类似于

的路径上使用 AL.EXE

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 工具

如果您可以让它使用 x64 版本的 AL.exe,问题就会消失。也就是说,在类似于以下的路径中使用 AL.EXE:

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\x64

Msbuild 通过使用其 TargetFrameworkSDKToolsDirectory 找到此路径。因此,假设在构建 x86 时该目录是正确的目录,下面的解决方法实质上是在构建 x64 时将 x64 子目录附加到路径上,否则保持原样:

  1. 创建 MsBuildAL1073WarningWorkaround.targets 文件(名称无关紧要)并将其添加到项目中。它具有以下内容:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <TargetFrameworkSDKToolsDirectory Condition=" '$(PlatformTarget)' == 'x64'">$(TargetFrameworkSDKToolsDirectory)$(PlatformTarget)\</TargetFrameworkSDKToolsDirectory>
      </PropertyGroup>
    </Project>  
    
  2. 编辑 .csproj 文件以在文件末尾附近导入此文件(您会在此处看到“要修改构建过程...”的注释):

     <Import Project="MsBuildAL1073WarningWorkaround.targets" />
     <!-- To modify your build process... -->
    

关于c# - 警告 MSB3270 架构不匹配/AL1073 针对不同的处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24908662/

相关文章:

c# - IF 是否比 IF-ELSE 表现更好?

javascript - AntiForgeryToken 无法跨同一解决方案的子项目进行验证

c++ - Visual Studio,在某个过滤器(解决方案资源管理器)内的所有文件中查找/替换文本

c++ - 为什么 auto_ptr 行为异常

c# - 在 Visual Studio Studio 中将所有函数/方法重命名为随机名称的方法

visual-studio - 如何舒适地设置 Visual Studio 2010 键盘快捷键,尤其是在使用 ReSharper 时?

c# - 当页面视频全屏时将 Webview2 切换到全屏

c# - 尾随点从 URL 中被截断

c++ - STL容器相当于Delphi集?

html - 用于在 Visual Studio 代码中引导 css 类的 Intellisense