$npx -y skills add Aaronontheweb/dotnet-skills --skill ilspy-decompileUnderstand implementation details of .NET code by decompiling assemblies. Use when you want to see how a .NET API works internally, inspect NuGet package source, view framework implementation, or understand compiled .NET binaries.
| 1 | # .NET Assembly Decompilation with ILSpy |
| 2 | |
| 3 | Use this skill to understand how .NET code works internally by decompiling compiled assemblies. |
| 4 | |
| 5 | ## Prerequisites |
| 6 | |
| 7 | - .NET SDK installed |
| 8 | - ILSpy command-line tool available via one of the following: |
| 9 | - `dnx ilspycmd` (if available in your SDK or runtime) |
| 10 | - `dotnet tool install --global ilspycmd` |
| 11 | |
| 12 | Both forms are shown below. Use the one that works in your environment. |
| 13 | |
| 14 | > Note: ILSpyCmd options may vary slightly by version. |
| 15 | > Always verify supported flags with `ilspycmd -h`. |
| 16 | |
| 17 | ## Quick start |
| 18 | |
| 19 | ```bash |
| 20 | # Decompile an assembly to stdout |
| 21 | ilspycmd MyLibrary.dll |
| 22 | # or |
| 23 | dnx ilspycmd MyLibrary.dll |
| 24 | |
| 25 | # Decompile to an output folder |
| 26 | ilspycmd -o output-folder MyLibrary.dll |
| 27 | ``` |
| 28 | |
| 29 | ## Common .NET Assembly Locations |
| 30 | |
| 31 | ### NuGet packages |
| 32 | |
| 33 | ```bash |
| 34 | ~/.nuget/packages/<package-name>/<version>/lib/<tfm>/ |
| 35 | ``` |
| 36 | |
| 37 | ### .NET runtime libraries |
| 38 | |
| 39 | ```bash |
| 40 | dotnet --list-runtimes |
| 41 | ``` |
| 42 | |
| 43 | ### .NET SDK reference assemblies |
| 44 | |
| 45 | ```bash |
| 46 | dotnet --list-sdks |
| 47 | ``` |
| 48 | |
| 49 | > Reference assemblies do not contain implementations. |
| 50 | |
| 51 | ### Project build output |
| 52 | |
| 53 | ```bash |
| 54 | ./bin/Debug/net8.0/<AssemblyName>.dll |
| 55 | ./bin/Release/net8.0/publish/<AssemblyName>.dll |
| 56 | ``` |
| 57 | |
| 58 | ## Core workflow |
| 59 | |
| 60 | 1. Identify what you want to understand |
| 61 | 2. Locate the assembly |
| 62 | 3. List types |
| 63 | 4. Decompile the target |
| 64 | |
| 65 | ## Commands |
| 66 | |
| 67 | ### Basic decompilation |
| 68 | |
| 69 | ```bash |
| 70 | ilspycmd MyLibrary.dll |
| 71 | ilspycmd -o ./decompiled MyLibrary.dll |
| 72 | ilspycmd -p -o ./project MyLibrary.dll |
| 73 | ``` |
| 74 | |
| 75 | ### Targeted decompilation |
| 76 | |
| 77 | ```bash |
| 78 | ilspycmd -t Namespace.ClassName MyLibrary.dll |
| 79 | ilspycmd -lv CSharp12_0 MyLibrary.dll |
| 80 | ``` |
| 81 | |
| 82 | ### View IL code |
| 83 | |
| 84 | ```bash |
| 85 | ilspycmd -il MyLibrary.dll |
| 86 | ``` |
| 87 | |
| 88 | ## Notes on modern .NET builds |
| 89 | |
| 90 | - ReadyToRun images may reduce readability |
| 91 | - Trimmed or AOT builds may omit code |
| 92 | - Prefer non-trimmed builds |
| 93 | |
| 94 | ## Legal note |
| 95 | |
| 96 | Decompiling assemblies may be subject to license restrictions. |