c# - System.Data 处理器架构设置为 AMD64

标签 c# .net tfs .net-assembly jit

TFS 已发出以下警告:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (1605): There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.dll", "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.

“发布”和“调试”配置均设置为使用“任何 CPU”作为事件解决方案平台。

我将 System.Data.dll 的副本复制到 TEMP 文件夹中,并通过 PowerShell 提取了有关此程序集的信息:

function ScanAssembly($assemblyPath) {
    [reflection.assemblyname]::GetAssemblyName($assemblyPath) 
}

$assemblyPath = "C:\TEMP\System.Data.dll"

$assemblyInfo = ScanAssembly($assemblyPath);
$assemblyInfo | fl;

我得到了以下输出:

Name                  : System.Data
Version               : 4.0.0.0
CultureInfo           : 
CultureName           : 
CodeBase              : file:///C:/TEMP/System.Data.dll
EscapedCodeBase       : file:///C:/TEMP/System.Data.dll
ProcessorArchitecture : Amd64
ContentType           : Default
Flags                 : PublicKey
HashAlgorithm         : SHA1
VersionCompatibility  : SameMachine
KeyPair               : 
FullName              : System.Data, Version=4.0.0.0, Culture=neutral, 
                        PublicKeyToken=...

出于某种原因,此程序集的 ProcessorArchitecture 设置为 Amd64。我对为什么将其设置为 Amd64 感到困惑,因为我在 Intel 处理器上运行 64 位操作系统。

这些警告不是显示限制,但我很难理解为什么我们会看到它们。如果我理解正确,当其中一个程序集为 Amd64 编译时,配置设置为任何 CPU,这意味着它将不再在任何 CPU 上工作——它只在 64 位 CPU 上工作。我不明白为什么 System.Data.dll 是为 Amd64 构建的。

谢谢。

最佳答案

关于为什么会出现这些错误,您是正确的。如果引用的程序集以特定框架为目标,编译器会警告您的应用程序无法在“任何 CPU”上运行,因为引用的程序集有限制。

我们在使用 System.Data 和其他 DLL 的测试和生产服务器上遇到了这个问题。我们通过安装 .Net Framework SDK 解决了这个问题。为此:

  1. 找到正确的 SDK。我们的环境是使用 Windows Server 2008 和 .Net Framework 4.5 设置的,因此我们使用了 Windows 8 SDK。 .
  2. 仅安装 .Net Framework 4.5 SDK(接受许可后,会出现一个带有多个复选框的屏幕;我只选中了最后一个)。

SDK 在 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5 中添加了新版本的 System.Data.dll。检查该程序集,您可以看到 ProcessorArchitecture 设置为 None .

Name                  : System.Data
Version               : 4.0.0.0
CultureInfo           :
CultureName           :
CodeBase              : file:///C:/Program Files (x86)/Reference\Assemblies/Microsoft/Framework/.NETFramework/v4.5/System.Data.dll
EscapedCodeBase       : file:///C:/Program%20Files%20(x86)/Reference%20Assemblies/Microsoft/Framework/.NETFramework/v4.5/System.Data.dll
ProcessorArchitecture : None
ContentType           : Default
Flags                 : PublicKey
HashAlgorithm         : SHA1
VersionCompatibility  : SameMachine
KeyPair               :
FullName              : System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

另一种选择是将您的项目配置为以 64 位处理器为目标(如果可以的话),但我们的团队选择了 SDK 路线。

关于c# - System.Data 处理器架构设置为 AMD64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18314670/

相关文章:

c# - 多线程,访问UI控制

c# - 从 dll 文件加载 Prism 模块(在启动时)

tfs - 如何在 TFS 构建定义中获取 checkin 评论/消息?

tfs - 有没有办法将父项链接到一组工作项

visual-studio-2012 - 如何检查我的工作区位于哪个变更集

c# - 仅当项目中存在属性时才在 aspx 中使用 Eval - 抛出 DataBinding 异常

c# - 如何从 foreach 循环中修改 foreach 迭代变量?

.net - 字符串的 MD5 哈希值

c# - 按住右键单击与 Manipulation 事件冲突

c# - 如何在 C# 中创建回调变量(真正的单播委托(delegate))