简体   繁体   中英

How to run ildasm on .Net core exe/assembly?

I'm trying to run ildasm (Intermediate Language Disassembler) installed as part of Visual Studio 2019 against .NetCore3.1 console app.

Use Developer command prompt of Visual Studio 2019 and run following command

ildasm.exe D:\\DotNet\\IntroductionToCsharp\\IntroductionToCsharp\\bin\\Debug\\netcoreapp3.1\\IntroductionToCsharp\\bin\\Debug\\netcoreapp3.1\\IntroductionToCsharp.exe

But following error occur:

'D:\\DotNet\\IntroductionToCsharp\\IntroductionToCsharp\\bin\\Debug\\netcoreapp3.1\\ IntroductionToCsharp.exe' has no valid CLR header and cannot be disassembled

此文件夹内容

Note: running the same command on non-Core (.Net Framework 4.x) exe works fine. Maybe there is something special needed to look at IL in .Net Core?

As it was pointed out already, the .exe in .NET Core is nothing more than a host. It's sole purpose is to get the CoreCLR loaded then JIT compile and execute your assembly's Main method. The code itself is stored within the .dll . You can check this with your favorite disassembler (ILDASM, JetBrains' dotPeek, ILSpy, etc).

Why could an IL disassembler work against an .exe in .NET Framework ? Because the executable would be a managed assembly, with a corresponding managed header. Unlike .NET Core, .NET Framework has extensive support from the Windows operating system's Image Loader to get everything set up and then run the managed code within the executable. See the second point discussed here .

NOTE: EXE in netcore exist just for "windows users", you should use always dll

See here

You can try this steps for netcore assembly (dll):

1 You need to have coreclr in the same folder of you dll netcore

2 (run commands in commandline VS)

ildasm.exe /all /out:<path to output>.il <path to dll>.dll

您应该将 ildasm 指向您的程序集文件(.dll 或 .exe),而不是您的项目文件夹,例如。

ldasm.exe D:\DotNet\IntroductionToCsharp\IntroductionToCsharp\bin\Debug\netcoreapp3.1\IntroductionToCsharp.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM