C# ildasm


ildasm stands for Intermediate Language Dis-assembler. What is it? It is a tool that lets you view the code that is generated by the C# compiler. You run it from the command prompt. The easy way to open a command prompt at the location of your code is to first install VS Productivity Power Tools and follow the instructions below. When you run it a window opens where you can see what code has been generated.

A good example of seeing the difference between your C# code and the code that is generated is to use auto-implemented properties. Below is an example of this.

using System;
namespace ConsoleApp2Junk
{
    public class Person
    {
        public DateTime Birthdate { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {

        }
    }
}

When you open your command prompt, type cd bin . Type cd debug. Type dir to see the files in this folder. We want to look at the IL code. To do this we can type ildasm followed by the name of the exe file. Below is a screenshot of what you will see if you followed this example. You will see the program class, the person class, a private backing field, and two methods: get and set. You also see the constructor, which is the default constructor.

Visual Studio Productivity Power Tools

This is a useful extension that you will probably want to install into Visual Studio. It will give you the ability to open a command prompt where your project is located on your drive with you having to manually navigate there with the DOS cd command. To check to see if it is already installed, in Visual Studio go to Tools > Extensions and Updates. If you scroll down the list of installed extensions and you find the following item.It is already installed. If it is not installed, on the left hand side go to Online and search for it and click the Install button and then you will probably need to re-start Visual Studio.

In VS Soultion Explorer, right-click the name of your project. In VS 2017 click Power Commands and click Open Command Prompt.