c# - 链接 : warning AL1073: Referenced assembly 'mscorlib.dll' targets a different processor

标签 c# .net visual-studio-2010 msbuild visual-studio-2013

我们正在使用 VS2013 和 .Net 4.5.1(最近迁移,但此错误来自 .Net 4.0)。只有在平台目标 x64 中编译项目时才会出现此错误。这真的是一个会在运行时中断的错误吗?为什么 MSBUILD 不能正确解析这个 mrcorlib.dll?这仅发生在 VS2010 中创建的项目中,而不会发生在新创建的项目中。我在这里错过了什么。我所有的第三方程序集都是 x64 位的。

在 TeamCity 构建服务器中,出现以下错误:

GenerateSatelliteAssemblies
[17:01:18]AL
[17:01:18]C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\AL.exe /culture:de /keyfile:..\..\MyApp.snk /out:obj\x64\Release\de\MyApp.Hardware.Softing.resources.dll /platform:x64 /template:obj\x64\Release\MyApp.Hardware.Softing.dll /embed:obj\x64\Release\MyApp.Hardware.Softing.Properties.Resources.de.resources
[17:01:18]ALINK warning AL1073: Referenced assembly 'mscorlib.dll' targets a different processor

最佳答案

解决办法:

可以通过使用与您尝试构建的平台(或位数)相匹配的 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# - 链接 : warning AL1073: Referenced assembly 'mscorlib.dll' targets a different processor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25365616/

相关文章:

.net - 在 .Net 应用程序中使用 Active Directory Web 服务

c# - 排序的列表项

c++ - 初始化 directX 11 时出现未处理的异常错误

c# - 在网站内添加 WCF 服务以进行发布

c# - 添加页码参数时,Report Services 在本地报告的 visual studio 调试器中崩溃

c# - 内联代码执行完成后是否将[写入其中的]方法保留在内存中?

c# - 从代码而不是从配置中为 log4net 启用文件日志记录

c# - Resharper 无法识别 web.config 中的命名空间别名

c# - 每次我运行 visual studio c# 应用程序时,Access 2007 中的所有记录都会删除

c# - 为什么我不能在 asp.net webforms 中执行此操作?