Browsing the .NET Framework source code from Visual Studio

.NetVisual Studio

.Net Problem Overview


I know that I can set up Visual Studio to debug through the .NET framework source code.

But is there a way that I can browse the code while NOT debugging - i.e., being able to press F12 or "Go to definition"?

I thought that if that feature isn't built into Visual Studio then there may be a plug-in that might add it?

.Net Solutions


Solution 1 - .Net

There is a very new feature in Visual Studio 2017 version 15.6

You can see decompiled source code without any plugin! Btw, Ref12 doesn't work for VS2017.

Tools > Options , expand Text Editor > C# > Advanced, and enable "Enable navigation to decompiled sources (experimental)".

Ref: https://docs.microsoft.com/en-us/visualstudio/ide/go-to-and-peek-definition?view=vs-2017#view-decompiled-source-definitions-instead-of-metadata-c

Solution 2 - .Net

With ReSharper it's possible to browse .NET sources by enabling ReSharper -> Options -> Tools -> External Sources -> Navigation to Sources. After enabling this option new menu item "Navigate To -> Decompiled Sources" appears by right click on type/method/whatever. Navigation also works with F12 for me.

Solution 3 - .Net

I just discovered this extension that pretty much addresses my problem. The only thing is that it opens the source in the browser rather than in Visual Studio, but it's no big deal because even in the browser you can click the source code to navigate to types etc.

It was presented on Scott Hanselman's blog a couple of days ago:

> Community member and fabulous coder Schabse Laks has created a Visual Studio extension for VS2010, 2012, and 2013! This extension sends calls to Go To Definition (or pressing F12 on a symbol) directly to the code online (when it's .NET Framework code, not yours). > > You can download this companion "Ref12" Visual Studio Extension now! Just Goto Definition on any .NET type we have source for and it'll launch your default browser so you can explore the .NET Framework source yourself! Thanks Schabse!

Update:

As per the comments, for VS 2022 and .NET Core, use this fork of the extension: https://marketplace.visualstudio.com/items?itemName=EfreyKong.Ref12-VS2022

Solution 4 - .Net

I downloaded the .NET Framework source code from here http://referencesource.microsoft.com/netframework.aspx.

Since I am working with .NET 4.0, I chose ".Net/4" from the list. (What is ".NET/8.0" in that list? No idea.)

I wrote some scripts to rearrange the bloody mess they give us:

  • Into a reasonable hierarchy of directories;
  • To remove duplicated code (why is every file doubled, or was my install bad?);
  • Rename all top-level namespaces to not conflict with native ones baked into Intellisense.
  • Example: System.Windows.Controls -> xSystem.Windows.Controls

Then follow these steps:

  1. Create a new Visual Studio project of type "Class Library"
  2. Remove all references -- yes, even the system ones.
  3. Drag/drop all of your massaged .NET code into the root of your project.
  4. Wait about 30 minutes for VS processing. VS will appear to freeze; be patient.

Intellisense/ReSharper still complains about heaps of problems, but now I can right click and select "Go to Declaration/Implementation".

Visual Studio is about 600MB with this project loaded.

Solution 5 - .Net

I am using Visual Studio 2013 Ultimate.

1. Choose menu: TOOLS \ Extensions and Updates...

enter image description here

2. Choose Visual Studio Gallery \ Search Results. Search term: Ref12.

enter image description here

3. Download then install.

enter image description here

4. Restart Visual Studio.

5. Try: Click mouse on Class or method, press F12 and see result at http://referencesource.microsoft.com/

Solution 6 - .Net

I've never tried this but supposedly the code is publicly available:

[Edit]

http://referencesource.microsoft.com/

Solution 7 - .Net

There is the .NET Mass Downloader, but I think the straightforward answer to your question is, no.

However I now see Microsoft has made the code more easily downloadable.

Nevertheless note that even for your own code, when not debugging, unless you have the project open, VS does not help you locate source code (even though when you find it yourself break points will work when you start debugging again, if the .pdb files correspond).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionXavier PoinasView Question on Stackoverflow
Solution 1 - .NetJohn_JView Answer on Stackoverflow
Solution 2 - .NettytyrytyView Answer on Stackoverflow
Solution 3 - .NetXavier PoinasView Answer on Stackoverflow
Solution 4 - .NetkevinarpeView Answer on Stackoverflow
Solution 5 - .NetDao Minh ThuView Answer on Stackoverflow
Solution 6 - .NetSteve WellensView Answer on Stackoverflow
Solution 7 - .NetMark HurdView Answer on Stackoverflow