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?
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?
A more advanced application for that you can find here: CodePlex - ApiChange
Examples:
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:
Open the Visual Studio Command Prompt (In Windows: menu Start/Programs/Microsoft Visual Studio/Visual Studio Tools/Visual Studio 2008 Command Prompt)
CD to the directory containing the DLL in question
Run corflags like this:
corflags MyAssembly.dll
You will get output something like this:
As per comments the flags above are to be read as following:
Below is a batch file that will run
corflags.exe
against alldlls
andexes
in the current working directory and all sub-directories, parse the results and display the target architecture of each.Depending on the version of
corflags.exe
that is used, the line items in the output will either include32BIT
, or32BITREQ
(and32BITPREF
). Whichever of these two is included in the output is the critical line item that must be checked to differentiate betweenAny CPU
andx86
. If you are using an older version ofcorflags.exe
(pre Windows SDK v8.0A), then only the32BIT
line item will be present in the output, as others have indicated in past answers. Otherwise32BITREQ
and32BITPREF
replace it.This assumes
corflags.exe
is in the%PATH%
. The simplest way to ensure this is to use aDeveloper Command Prompt
. Alternatively you could copy it from it's default location.If the batch file below is run against an unmanaged
dll
orexe
, it will incorrectly display it asx86
, since the actual output fromCorflags.exe
will be an error message similar to:DotPeek from JetBrians provides quick and easy way to see msil(anycpu), x86, x64
Another way to check the target platform of a .NET assembly is inspecting the assembly with .NET Reflector...
@#~#€~! I've just realized that the new version is not free! So, correction, if you have a free version of .NET reflector, you can use it to check the target platform.