简体   繁体   English

从 Visual Studio 浏览 .NET Framework 源代码

[英]Browsing the .NET Framework source code from Visual Studio

I know that I can set up Visual Studio to debug through the .NET framework source code .我知道我可以设置 Visual Studio 以通过 .NET 框架源代码进行调试

But is there a way that I can browse the code while NOT debugging - ie, being able to press F12 or "Go to definition"?但是有没有一种方法可以让我在不调试的同时浏览代码——即,能够按 F12 或“转到定义”?

I thought that if that feature isn't built into Visual Studio then there may be a plug-in that might add it?我想如果该功能没有内置到 Visual Studio 中,那么可能会有一个插件可以添加它?

There is a very new feature in Visual Studio 2017 version 15.6 Visual Studio 2017版本15.6 中有一个非常新的功能

You can see decompiled source code without any plugin!不用任何插件就可以看到反编译的源码! Btw, Ref12 doesn't work for VS2017.顺便说一句,Ref12 不适用于 VS2017。

Tools > Options , expand Text Editor > C# > Advanced , and enable " Enable navigation to decompiled sources (experimental) ".工具>选项,展开文本编辑器> C# >高级,并启用“启用导航到反编译源(实验) ”。

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

With ReSharper it's possible to browse .NET sources by enabling ReSharper -> Options -> Tools -> External Sources -> Navigation to Sources.使用 ReSharper,可以通过启用 ReSharper -> Options -> Tools -> External Sources -> Navigation to Sources 来浏览 .NET 源。 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.导航也适用于我的 F12。

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.唯一的问题是它在浏览器中而不是在 Visual Studio 中打开源代码,但这没什么大不了的,因为即使在浏览器中,您也可以单击源代码以导航到类型等。

It was presented on Scott Hanselman's blog a couple of days ago:几天前,它出现在 Scott Hanselman 的博客上

Community member and fabulous coder Schabse Laks has created a Visual Studio extension for VS2010, 2012, and 2013!社区成员和出色的编码员 Schabse Laks 为 VS2010、2012和 2013 创建了 Visual Studio 扩展! 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).此扩展将调用 Go To Definition(或在符号上按 F12)直接发送到在线代码(如果它是 .NET Framework 代码,而不是您的代码)。

You can download this companion "Ref12" Visual Studio Extension now !您现在可以下载这个配套的“Ref12”Visual Studio 扩展 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!只需在我们拥有源代码的任何 .NET 类型上转到定义,它就会启动您的默认浏览器,以便您可以自己探索 .NET Framework 源代码! Thanks Schabse!谢谢沙布斯!

I downloaded the .NET Framework source code from here http://referencesource.microsoft.com/netframework.aspx .我从这里下载了 .NET Framework 源代码http://referencesource.microsoft.com/netframework.aspx

Since I am working with .NET 4.0, I chose ".Net/4" from the list.由于我使用 .NET 4.0,因此我从列表中选择了“.Net/4”。 (What is ".NET/8.0" in that list? No idea.) (该列表中的“.NET/8.0”是什么?不知道。)

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.重命名所有顶级命名空间,以免与融入 Intellisense 的本机命名空间发生冲突。
  • Example: System.Windows.Controls -> xSystem.Windows.Controls示例:System.Windows.Controls -> xSystem.Windows.Controls

Then follow these steps:然后按照以下步骤操作:

  1. Create a new Visual Studio project of type "Class Library"创建一个“类库”类型的新 Visual Studio 项目
  2. Remove all references -- yes, even the system ones.删除所有引用——是的,甚至是系统引用。
  3. Drag/drop all of your massaged .NET code into the root of your project.将所有经过处理的 .NET 代码拖放到项目的根目录中。
  4. Wait about 30 minutes for VS processing.等待大约 30 分钟进行 VS 处理。 VS will appear to freeze; VS 会出现冻结; be patient.要有耐心。

Intellisense/ReSharper still complains about heaps of problems, but now I can right click and select "Go to Declaration/Implementation". Intellisense/ReSharper 仍然抱怨大量问题,但现在我可以右键单击并选择“转到声明/实施”。

Visual Studio is about 600MB with this project loaded.加载此项目后,Visual Studio 大约有 600MB。

I am using Visual Studio 2013 Ultimate.我正在使用 Visual Studio 2013 Ultimate。

1. Choose menu: TOOLS \\ Extensions and Updates... 1.选择菜单:工具\\扩展和更新...

在此处输入图片说明

2. Choose Visual Studio Gallery \\ Search Results . 2.选择Visual Studio Gallery \\ Search Results Search term: Ref12 .搜索词: Ref12

在此处输入图片说明

3. Download then install. 3.下载然后安装。

在此处输入图片说明

4. Restart Visual Studio. 4.重新启动 Visual Studio。

5. Try: Click mouse on Class or method, press F12 and see result at http://referencesource.microsoft.com/ 5.尝试:在类或方法上单击鼠标,按F12并在http://referencesource.microsoft.com/ 上查看结果

I've never tried this but supposedly the code is publicly available:我从来没有试过这个,但据说代码是公开的:

[Edit] [编辑]

http://referencesource.microsoft.com/ http://referencesource.microsoft.com/

There is the .NET Mass Downloader , but I think the straightforward answer to your question is, no..NET Mass Downloader ,但我认为对您的问题的直接答案是,不。

However I now see Microsoft has made the code more easily downloadable.但是,我现在看到 Microsoft 使代码更易于下载。

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).不过请注意,即使对于您自己的代码,在不调试时,除非您打开了项目,否则 VS 不会帮助您定位源代码(即使您自己找到了断点,当您再次开始调试时,如果.pdb文件对应)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在Visual Studio中为引用的库添加源代码浏览? - Is there any way to add source code browsing for referenced libraries in Visual Studio? Visual Studio Debugger没有进入.NET框架源代码 - Visual Studio Debugger not stepping into .NET framework source code 在Visual Studio 2012中调试.NET Framework源代码? - Debug .NET Framework Source Code in Visual Studio 2012? .Net 框架的 Visual Studio 代码 - Visual Studio Code for .Net Framework 如何在Visual Studio 2017中调试.NET 4.6框架源代码? - How do I debug .NET 4.6 framework source code in Visual Studio 2017? 使用.Net Framework v4.8和Visual Studio 2019查询TFS 2015源代码存储库DateTime属性 - Querying TFS 2015 Source Code Repository DateTime Properties with .Net Framework v4.8 and Visual Studio 2019 具有Visual Studio代码的F#.net框架 - F# .net framework with visual studio code Visual Studio Performance Profiler - 源信息不可用 - .NET Framework 3.5 - Visual Studio Performance Profiler - Source Information is Not Available - .NET Framework 3.5 Visual Studio Code .NET 框架在通过统一启动时不起作用 - Visual Studio Code .NET framework not working when launched through unity 是否可以从源代码编译/自定义.net framework / asp net - Is it possible to compile/customize the .net framework/asp net from source code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM