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

后端 未结 4 507
星月不相逢
星月不相逢 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 17:53

    Thanks Adrian! I've rewritten the snippet in PowerShell so I could use it on the server.

    #USAGE #1
    # Get-Bitness (dir *.dll | select -first 1)
    #USAGE #2
    # Get-Bitness "C:\vs\projects\bestprojectever\bin\debug\mysweetproj.dll"
    function Get-Bitness([System.IO.FileInfo]$assemblyFile)
    {
        $peKinds = new-object Reflection.PortableExecutableKinds
        $imageFileMachine = new-object Reflection.ImageFileMachine
        $a = [Reflection.Assembly]::LoadFile($assemblyFile.Fullname)
        $a.ManifestModule.GetPEKind([ref]$peKinds, [ref]$imageFileMachine)
    
        return $peKinds
    }
    

提交回复
热议问题