ILDasm with .Net Core

Need to Convert CIL Code into Text? Try ILDasm!

 

The C# compiler converts C# code to common intermediate language (CIL) code and not to machine code. The processor can directly understand machine code, but CIL code needs to be converted before the processor can execute it.

Consider using the Intermediate Language Disassembler (ILDasm) when you need to convert CIL code into text. ILDasm is a CIL disassembler provided in C# that is used to view the assembly content of all classes and methods available in .NET application. It is available in Visual Studio and .NET SDK.

The following six steps will help you master this tool by providing a sample of how to use ildasm with a .NET Core project.

  1. From the command prompt, change directories into an empty folder called “HelloWorld”
    mkdir HelloWorld; cd HelloWorld
  2. Create a .NET Core console application
    dotnet new console
  3. Add a package reference to the project for dotnet-ildasm (the latest version)
    dotnet add package dotnet-ildasm -v '*'
  4. Replace the PackageReference node with the DotNetCliToolReference.
    (type .\HelloWorld.csproj) -replace '<PackageReference Include="dotnet-ildasm"','<DotNetCliToolReference Include="dotnet-ildasm"' | Set-Content -Path .\HelloWorld.csproj
  5. Run dotnet restore in order to download the package (only required for .NET Core versions prior to 2.0)
    dotnet restore
  6. At this point, dotnet should have a new verb, ildasm, that you can use to extract the CIL from your assembly as text

     

Want the full output?

Here’s the output from running the above commands.

Questions? Post them in the comments.

 

Join the Conversation

  1. Erin Wissing

2 Comments

Your email address will not be published. Required fields are marked *

  1. Hello,
    Probably you have a short tutorial how to use dotnet Core ILasm. Please share with us if you know how to do that please.