How to Tell if a .NET Assembly Was Compiled as x86, x64 or Any CPU

后端 未结 4 503
星月不相逢
星月不相逢 2020-12-05 17:21

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 com

4条回答
  •  北海茫月
    2020-12-05 18:03

    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
    

    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)
    

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

提交回复
热议问题