问题
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?
回答1:
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.
回答2:
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
回答3:
You should point ildasm to your assembly file (.dll or .exe) not your project folder for ex.
ldasm.exe D:\DotNet\IntroductionToCsharp\IntroductionToCsharp\bin\Debug\netcoreapp3.1\IntroductionToCsharp.exe
来源:https://stackoverflow.com/questions/59818364/how-to-run-ildasm-on-net-core-exe-assembly