Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2019 F12 to decompiled source for .NET Core projects

Tags:

.net-core

I very often use the Visual Studio F12 to decompiled source feature. When I do this against framework classes in a .NET Core project I very often end up looking at some sort of reference assembly that has no implementation code, just stubs, e.g

enter image description here

Is there any way of getting it to go straight to the actual implementation code instead?

like image 830
Duncan Smart Avatar asked Nov 10 '19 12:11

Duncan Smart


People also ask

How do I decompile source code in Visual Studio?

To open the Modules window, select Debug > Windows > Modules. Once you have identified a module that requires decompilation, you can right-click on the module and select “Decompile Source to Symbol File”.

Can C# code be decompiled?

Generated code is C# onlyDecompilation only generates source code files in C#. There is no option to generate files in any other language.

What is the best C# decompiler?

DnSpy . This decompiler is characterized by its large number of options and tools and above all by its UI design. Using DnSpy (for most . NET developers) is easier and more intuitive than the decompilers mentioned above. DnSpy is a very versatile disassembler, supporting C#, VB, F# code and more.


2 Answers

So you see at the top where it lists .Ref at the end of the package name? I'm not positive but I suspect this is trimmed down version of the DLL that doesn't include the full source.

If you search for the dll elsewhere you should be able to find the dll with the full source and decompile that with a standalone decompiler.

So for your example you can find the full dll at C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\3.0.0\Microsoft.AspNetCore.Authentication.Cookies.dll

Personally I prefer using the free decompiler offered by JetBrains called dotPeek. It allows you to navigate directly to the decompiled source using F12, however this will only lead you back to where you are stuck now. BUT if you open the path I listed above for the full DLL and open that in dotPeek, you'll get the full decompiled source code.

Decompiled Source As far as I know there's no way to lookup the actual DLL via keyboard shortcut inside the IDE, you have to find the DLL yourself and open it in a decompiler.

like image 88
Nick Henry Avatar answered Jun 13 '23 04:06

Nick Henry


Assuming you've downloaded the ILSpy visual studio extension... There is a way to decompile using a keyboard shortcut. Tools->Options->Environment->Keyboard

Options Window

Press a set of keys for the keyboard shortcut. (I used ctrl i l). Click Assign->OK

Pressing the above keyboard shortcut will now open the selected code decompiled in a new window of ILSpy.

like image 45
Elchanan Razin Avatar answered Jun 13 '23 02:06

Elchanan Razin