How can I determine if a .NET assembly was built for x86 or x64?

后端 未结 15 870
面向向阳花
面向向阳花 2020-11-22 09:08

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?

15条回答
  •  抹茶落季
    2020-11-22 09:29

    Just for clarification, CorFlags.exe is part of the .NET Framework SDK. I have the development tools on my machine, and the simplest way for me determine whether a DLL is 32-bit only is to:

    1. Open the Visual Studio Command Prompt (In Windows: menu Start/Programs/Microsoft Visual Studio/Visual Studio Tools/Visual Studio 2008 Command Prompt)

    2. CD to the directory containing the DLL in question

    3. Run corflags like this: corflags MyAssembly.dll

    You will get output something like this:

    Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  3.5.21022.8
    Copyright (c) Microsoft Corporation.  All rights reserved.
    
    Version   : v2.0.50727
    CLR Header: 2.5
    PE        : PE32
    CorFlags  : 3
    ILONLY    : 1
    32BIT     : 1
    Signed    : 0
    

    As per comments the flags above are to be read as following:

    • Any CPU: PE = PE32 and 32BIT = 0
    • x86: PE = PE32 and 32BIT = 1
    • 64-bit: PE = PE32+ and 32BIT = 0

提交回复
热议问题