63

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?

2
  • This feature can only work when you have the projects loaded in a solution so that IntelliSense can parse them. Clearly you don't want a solution that builds all the .NET framework assemblies. Commented May 21, 2012 at 17:57
  • Link is broken, here's the Wayback version: web.archive.org/web/20150822081658/http://blogs.msdn.com:80/b/… Commented Jan 9, 2019 at 18:24

8 Answers 8

27

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://learn.microsoft.com/en-us/visualstudio/ide/go-to-and-peek-definition?view=vs-2017#view-decompiled-source-definitions-instead-of-metadata-c

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it's a good feature but it is showing decompiled code, not showing the original source code (that is available online).
18

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.

5 Comments

It only shows the interface information but not the actual source code (contents of the methods) itself. Or am I doing something wrong?
Sorry. My bad. It works now. I guess I had to rebuild ;-) Sweet! Now I can F12 into .NET sources!
Hi @Xan-KunClark-Davis, how did you start the code browsing? Do you ctrl-click a type? I rebuilt the project and it still shows the decompiled class.
@OgrishMan Sorry, my bad. I actually see the code ReSharper decompiles with the help of downloaded symbol files. It show more than just an interface, but is definately NOT the real source code (e.g.: no comments in it). Again, sorry for the confusion and for getting you hopes up. I think this should be clarified in the answer.
Beware before installing Resharper. This is a paid tool, and though there is a trial period, using it requires you to sign in using an IntelliJ/social media account to provide them your email and personal details, and also agree to an end user license agreement on first run.
17

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

5 Comments

Doesn't work with webapi either by the looks of things
can i check my .net framework version in my git Hub source code??
Brilliant! I installed Ref12 VS2022 (in Visual Studio 2022) and, bada-bing, bada-boom, clicking on an ASP.NET Core thing and pressing F12 takes me to a nifty online source code browser with the code for the ASP.NET Core thing displayed.
The original Github Repo by Schabse Laks had not been updated for several years, and has been forked by Efrey Kong, and the extension updated to support Visual Studio 2022, and .Net Core. This new version is also named Ref12, and can be found on the Visual Studio Marketplace, here: marketplace.visualstudio.com/…
Unfortunately, it does not support .Net core in Visual Studio 2019.
6

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.

2 Comments

could you share your scripts or your final .sln file?
yes, would be great to share the final result, so all others does not have to do the same 'boring' procedure of renaming and so on.
5

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/

2 Comments

Thanks, but this is a duplicate of the answer I posted 1 year before.
@XavierPoinas, That is right. However this post answers the question in another perspective. Someone understands answers better including steps or images. Others prefer raw text.
2

VS2022

Old thread, new VS ☺

Go to
Tools > Options
then
Text Editor > C# > Advanced
under
Go To Definition
select
Enable navigation to Source Link and Embedded Sources

Screenshot of Go To Definition section

In case you need it to work in debugging too

Make sure that under
Debugging > General
source server and Source Link are enabled.

enter image description here

Resharper

Unfortunately, I couldn't get it to work in conjunction with ReSharper, since then it always decompiles. So I had to disable ReSharper's navigation feature completely.

2 Comments

The question was "while NOT debugging", and your answer is related to debugging.
hope that edit clarifies it
1

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

[Edit]

http://referencesource.microsoft.com/

1 Comment

Sure - that's what VS uses in debug mode (when set up as in the above link). But how do I set up VS so that it can find and display the source code for me when I am not debugging?
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.