如何判断一个.NET程序集编译为86,64或任何CPU [英] How to Tell if a .NET Assembly Was Compiled as x86, x64 or Any CPU

查看:444
本文介绍了如何判断一个.NET程序集编译为86,64或任何CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是发现(不访问源项目).NET程序集DLL是否被编译为'86','64'或'任何CPU'?

What's the easiest way to discover (without access to the source project) whether a .NET assembly DLL was compiled as 'x86', 'x64' or 'Any CPU'?

更新:一个命令行实用程序足以满足我的眼前需求,但只是为了完整起见,如果有人想告诉我该怎么做编程那简直是太感兴趣,我敢肯定。

Update: A command-line utility was sufficient to meet my immediate needs, but just for the sake of completeness, if someone wants to tell me how to do it programmatically then that would be of interest too, I'm sure.

推荐答案

如果你只是想找到这一点上给定的DLL,那么你可以使用的 CorFlags 工具,它是Windows SDK的一部分:

If you just want to find this out on a given dll, then you can use the CorFlags tool that is part of the Windows SDK:

CorFlags.exe assembly.dll


如果你想要做的使用code呢,一起来看看在的 GetPEKind 方法模块类:


If you want to do it using code, take a look at the GetPEKind method of the Module class:

Assembly assembly = Assembly.LoadFrom("path to dll");
PortableExecutableKinds peKind;
ImageFileMachine imageFileMachine;
assembly.ManifestModule.GetPEKind(out peKind, out imageFileMachine)

然后,您需要检查 peKind 来检查它的价值。请参阅 MSDN文档 PortableExecutableKinds 了解更多信息。

You then need to examine the peKind to check its value. See the MSDN docs for PortableExecutableKinds for more info.

这篇关于如何判断一个.NET程序集编译为86,64或任何CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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