如何确定 .NET 程序集是为 x86 还是 x64 构建的? [英] How can I determine if a .NET assembly was built for x86 or x64?

查看:29
本文介绍了如何确定 .NET 程序集是为 x86 还是 x64 构建的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个任意的 .NET 程序集列表.

我需要以编程方式检查每个 DLL 是否是为 x86(而不是 x64 或任何 CPU)构建的.这可能吗?

解决方案

System.Reflection.AssemblyName.GetAssemblyName(string assemblyFile)

您可以从返回的 AssemblyName 实例中检查程序集元数据:

使用 PowerShell:

<前>[36] C:> [reflection.assemblyname]::GetAssemblyName("${pwd}Microsoft.GLEE.dll") |佛罗里达州名称 : Microsoft.GLEE版本:1.0.0.0文化信息 :代码库:file:///C:/projects/powershell/BuildAnalyzer/...转义代码库:file:///C:/projects/powershell/BuildAnalyzer/...处理器架构:MSIL标志:公钥哈希算法:SHA1版本兼容性:SameMachine密钥对:全名:Microsoft.GLEE,版本=1.0.0.0,文化=中性...

此处,ProcessorArchitecture 标识目标平台.

  • Amd64:基于 x64 架构的 64 位处理器.
  • Arm:ARM 处理器.
  • IA64:仅限 64 位 Intel Itanium 处理器.
  • MSIL:在处理器和每字位数方面中立.
  • X86:32 位英特尔处理器,可以是原生的,也可以是在 64 位平台 (WOW64) 上的 Windows 环境中.
  • :处理器和每字位的未知或未指定组合.

我在本示例中使用 PowerShell 来调用该方法.

I've got an arbitrary list of .NET assemblies.

I need to programmatically check if each DLL was built for x86 (as opposed to x64 or Any CPU). Is this possible?

解决方案

Look at System.Reflection.AssemblyName.GetAssemblyName(string assemblyFile)

You can examine assembly metadata from the returned AssemblyName instance:

Using PowerShell:

[36] C:> [reflection.assemblyname]::GetAssemblyName("${pwd}Microsoft.GLEE.dll") | fl

Name                  : Microsoft.GLEE
Version               : 1.0.0.0
CultureInfo           :
CodeBase              : file:///C:/projects/powershell/BuildAnalyzer/...
EscapedCodeBase       : file:///C:/projects/powershell/BuildAnalyzer/...
ProcessorArchitecture : MSIL
Flags                 : PublicKey
HashAlgorithm         : SHA1
VersionCompatibility  : SameMachine
KeyPair               :
FullName              : Microsoft.GLEE, Version=1.0.0.0, Culture=neut... 

Here, ProcessorArchitecture identifies target platform.

  • Amd64: A 64-bit processor based on the x64 architecture.
  • Arm: An ARM processor.
  • IA64: A 64-bit Intel Itanium processor only.
  • MSIL: Neutral with respect to processor and bits-per-word.
  • X86: A 32-bit Intel processor, either native or in the Windows on Windows environment on a 64-bit platform (WOW64).
  • None: An unknown or unspecified combination of processor and bits-per-word.

I'm using PowerShell in this example to call the method.

这篇关于如何确定 .NET 程序集是为 x86 还是 x64 构建的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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