如何确定 .NET 程序集是为 x86 还是 x64 构建的?

编程入门 行业动态 更新时间:2024-10-11 19:15:55
本文介绍了如何确定 .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 构建的?

本文发布于:2023-11-02 12:11:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!