构建 x64 版本时 CS1607 编译器警告 [英] CS1607 compiler warning when building the x64 version

查看:23
本文介绍了构建 x64 版本时 CS1607 编译器警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Windows Server 2003 上使用 Visual Stuido 2008 构建 x64 版本的 .net 应用程序时我明白了

when i build x64 version of my .net app with Visual Stuido 2008 on Windows Server 2003 i get

警告 CS1607:程序集生成 -- 引用的程序集mscorlib.dll"针对不同的处理器

warning CS1607: Assembly generation -- Referenced assembly 'mscorlib.dll' targets a different processor

这是否意味着我还没有安装 x64 版本的 .NET?

Does it mean I have not installed x64 version of .NET?

完整报告在这里

16>C:WINDOWSMicrosoft.NETFrameworkv3.5Csc.exe/noconfig/nowarn:1701,1702/平台:x64/错误报告:提示/定义:调试;跟踪/reference:.........BINJfc.DealingJfc.Configuration.ConfigurationLayer.dll/reference:.........BINJfc.DealingJfc.Sys.dll/reference:D:ProjectsdzhukovSourceCode_Integration_branchTradeProcessorJfcQuikExportinx64DebugQuikExport.dll/reference:D:ProjectsdzhukovSourceCode_Integration_branchSamplesJFCFxGateQuoteFeedWcfRemoteControlinx64DebugQuoteFeedWcfRemoteControl.dll/reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.configuration.dll/reference:"c:Program FilesReference程序集MicrosoftFrameworkv3.5System.Core.dll"/reference:"c:Program FilesReferenceAssembliesMicrosoftFrameworkv3.5System.Data.DataSetExtensions.dll"/reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Data.dll/reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.dll/reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Messaging.dll/reference:"C:Program FilesReference程序集MicrosoftFrameworkv3.0System.Runtime.Serialization.dll"/reference:"C:Program FilesReference程序集MicrosoftFrameworkv3.0System.ServiceModel.dll"/reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Xml.dll/reference:"c:Program FilesReference程序集MicrosoftFrameworkv3.5System.Xml.Linq.dll"/debug+/debug:full/filealign:512/out:objx64DebugFeedRawQuotes.exe/target:exe FeedRawQuotes.csFeedRawQuotesConfiguration.csMSMQFeed.cs 程序.csPropertiesAssemblyInfo.cs 警告CS1607:汇编生成——引用的程序集System.Data.dll"针对不同的处理器警告CS1607:汇编生成——引用的程序集mscorlib.dll"针对不同的处理器

16>C:WINDOWSMicrosoft.NETFrameworkv3.5Csc.exe /noconfig /nowarn:1701,1702 /platform:x64 /errorreport:prompt /define:DEBUG;TRACE /reference:..........BINJfc.DealingJfc.Configuration.ConfigurationLayer.dll /reference:..........BINJfc.DealingJfc.Sys.dll /reference:D:ProjectsdzhukovSourceCode_Integration_branchTradeProcessorJfcQuikExportinx64DebugQuikExport.dll /reference:D:ProjectsdzhukovSourceCode_Integration_branchSamplesJFCFxGateQuoteFeedWcfRemoteControlinx64DebugQuoteFeedWcfRemoteControl.dll /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.configuration.dll /reference:"c:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Core.dll" /reference:"c:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Data.DataSetExtensions.dll" /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Data.dll /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.dll /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Messaging.dll /reference:"C:Program FilesReference AssembliesMicrosoftFrameworkv3.0System.Runtime.Serialization.dll" /reference:"C:Program FilesReference AssembliesMicrosoftFrameworkv3.0System.ServiceModel.dll" /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Xml.dll /reference:"c:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /out:objx64DebugFeedRawQuotes.exe /target:exe FeedRawQuotes.cs FeedRawQuotesConfiguration.cs MSMQFeed.cs Program.cs PropertiesAssemblyInfo.cs warning CS1607: Assembly generation -- Referenced assembly 'System.Data.dll' targets a different processor warning CS1607: Assembly generation -- Referenced assembly 'mscorlib.dll' targets a different processor

推荐答案

这是一个正常的警告,当你明确定位 x64 时,你总会得到它.在运行时不会有问题,因为在 64 位机器上,GAC 存储了 64 位特定版本的 mscorlib.dll.

This is a normal warning, you will always get it when you explicitly target x64. It won't be a problem at runtime because on a 64-bit machine, the GAC stores a 64-bit specific version of mscorlib.dll.

长版:几个 .NET 程序集包含非托管代码.这使他们对使用它们的过程的位数敏感.Mscorlib.dll 是其中之一,System.Data.dll 和 WPF 程序集是其他示例.Microsoft 通过构建这些程序集的两个版本来解决这个问题,一个 32 位版本和一个 64 位版本.GAC 可以存储它们,由 AssemblyName.ProcessorArchitecture 属性解析.此属性的正常"设置是 MSIL,当程序集包含纯 IL 时使用.然后,32 位和 64 位进程都可以使用该程序集的单个副本.

Long version: several .NET assemblies contain unmanaged code. Which makes them sensitive to the bitness of the process that uses them. Mscorlib.dll is one of them, System.Data.dll and the WPF assemblies are other examples. Microsoft resolved this by building two versions of those assemblies, a 32-bit one and a 64-bit one. The GAC can store them both, resolved by the AssemblyName.ProcessorArchitecture property. The 'normal' setting for this property is MSIL, used when the assembly contains pure IL. A single copy of the assembly can then be used by both a 32-bit and a 64-bit process.

编译器使用的参考程序集是 .NET 程序集的副本.编译器仅将它们用于元数据.然而,这些副本是 32 位程序集的副本,对于包含非托管代码的程序集,它们会将 ProcessArchitecture 设置为 X86.

The reference assemblies used by the compiler are a copy of the .NET assemblies. The compiler uses them purely for their metadata. Those copies are however copies of the 32-bit assemblies, they'll have the ProcessArchitecture set to X86 for assemblies that contain unmanaged code.

您可以看到它的去向,您正在为 x64 进行编译,并且编译器会看到一个 x86 参考程序集.足以生成警告如果您还提供程序集的 x64 版本,该程序将运行"..NET 程序集肯定是这种情况,但不一定适用于您自己的程序集.

You can see where this goes, you are compiling for x64 and the compiler sees an x86 reference assembly. Enough to generate a warning "this program is going to work only if you also provide the x64 version of the assembly". Which is certainly the case for .NET assemblies, but not necessarily for your own.

也许值得注意的是,这已在 .NET 4.0 中解决.它使用非常不同的参考程序集,这些程序集存储在 C:Program Files (x86)Reference Assemblies 中.与 v2 参考程序集不同,它们与 GAC 中的副本截然不同.所有的 MSIL 都从它们中剥离出来,它们只包含元数据.并且是 AnyCPU,因此不再发出警告.用于创建它们的工具很有趣,遗憾的是 Microsoft 没有与我们分享.

Perhaps notable is that this was solved in .NET 4.0. It uses very different reference assemblies, which are stored in C:Program Files (x86)Reference Assemblies. Unlike the v2 reference assemblies, they are drastically different from the copy in the GAC. All the MSIL was stripped from them, they only contain metadata. And are AnyCPU, thus no warning anymore. The tool that was used to create them is interesting, unfortunately Microsoft doesn't share it with us.

Fwiw,明确针对 x64 几乎总是错误的做法.它只对 EXE 程序集真正重要,因为它决定了进程的位数.DLL 程序集没有选择,适合它们的构建设置是 Any CPU,因此它们可以双向工作.罕见的例外是 DLL 已知依赖于非托管组件,通常是 COM 服务器.此类组件通常仅可用作 32 位图像,当您尝试在 64 位进程中加载​​它们(类未注册")时,您会收到难以诊断的错误消息.通过强制它们以 x86 为目标,您将获得另一个难以诊断的异常,这可能更容易一些,BadImageFormatException.依赖仅在 64 位代码中可用的非托管代码是非常罕见的,因此针对 x64 没有多大意义.

Fwiw, explicitly targeting x64 is almost always the wrong thing to do. It only really matters on the EXE assembly since that is the one that determines the bitness of the process. A DLL assembly doesn't have a choice, the appropriate build setting for them is Any CPU so they can work both ways. The rare exception is that the DLL has a known dependency on a unmanaged component, typically a COM server. Such components are typically only available as 32-bit images, you get a hard to diagnose error message when you try to load them in a 64-bit process ("Class not registered"). By forcing them to target x86, you'd get another hard to diagnose exception that is perhaps a bit easier on the eyes, BadImageFormatException. Having a dependency on unmanaged code that is only available in 64-bit code is quite rare, therefore targeting x64 doesn't make much sense.

这篇关于构建 x64 版本时 CS1607 编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆