dnspy

dnSpy

dnSpy is a .NET assembly browser, decompiler, debugger, and editor. It is useful when you have a compiled .NET program or library and want to inspect the C#-like source that was produced from the assembly. It can also export a whole assembly as a C# project, which is the workflow I usually want when I need to search and compare code across many files.

opening an assembly

Start dnSpy, then use File -> Open... and choose the assembly you want to inspect. For a Unity game using the Mono scripting backend, the main game code is usually in a managed DLL under a path like:

GameName_Data\Managed\Assembly-CSharp.dll

After opening the DLL, dnSpy shows the assembly tree on the left. Expanding namespaces and classes lets you browse decompiled code directly in the editor pane.

saving the decompiled project

To save the decompiled code as files, use File -> Export to Project.... Pick an empty output folder. dnSpy will write a Visual Studio style project, usually including a solution file, a project file, and one C# file per decompiled type.

The output will look roughly like this:

decompiled-output\
  solution.sln
  Assembly-CSharp\
    Assembly-CSharp.csproj
    SomeNamespace\
      SomeClass.cs

Once it is exported, the folder can be searched with regular tools, opened in an editor, or compared against a previous export after an application update.

notes

Save Code... is useful for saving the currently viewed decompiled file. Export to Project... is the one to use when you want the whole assembly saved as a project.

If the program was built with native/IL2CPP instead of regular managed .NET assemblies, this workflow may not produce the game logic directly. In that case, a different toolchain is needed.


edit this page