简体   繁体   English

如何使用F12在Visual Studio中查看C#代码详细信息?

[英]How to see the c# code detail in visual studio using F12?

I'm the new of c# and visual studio. 我是c#和Visual Studio的新手。 when I use the F12 to go to definition, but sometime it didn't work. 当我使用F12进行定义时,但有时不起作用。 it just showed me the a code without the body/logic of the methods. 它只是向我展示了一个没有方法的主体/逻辑的代码。

Someone told me because of dll , but I really don't know how to do can see the detailed code in this case. 有人因为dll告诉我,但是我真的不知道该怎么办才能看到这种情况下的详细代码。 Thanks. 谢谢。

As others said, it's because all VS has to go on is the DLL, which doesn't contain the source, only method signatures. 正如其他人所说,这是因为所有VS都必须继续执行DLL,该DLL不包含源代码,而仅包含方法签名。

But what can you do about it? 但是你能做什么呢?

A few things. 一些东西。

  1. Try ReSharper, which has a built-in decompiler and can show you some code (note that it won't be formatted and with variable names of the original, but it's usually better than nothing). 尝试ReSharper,它具有内置的反编译器,并且可以向您显示一些代码(请注意,它不会被格式化并且具有原始变量名,但通常总比没有好。)
  2. If you don't have ReSharper, you can use the free JetBrains dotPeek product, although that's not integrated into Visual Studio. 如果没有ReSharper,则可以使用免费的JetBrains dotPeek产品,尽管该产品尚未集成到Visual Studio中。
  3. If you reference from Nuget.org, then you should be able to turn on an option in VS that will download sources (if provided by the package author) in the form of pdb files. 如果从Nuget.org引用,则应该能够在VS中打开一个选项,该选项将以pdb文件的形式下载源(如果由包作者提供)。 This is the best experience. 这是最好的体验。
  4. If possible, get your hands on some matching pdb files. 如果可能,请使用一些匹配的pdb文件。 Either get them direct, build from source etc. 直接获取它们,从源代码构建等等。

This is because you didn't add reference as a project but you are pointing to a dll or exe using Browse tab in Add Reference dialog. 这是因为您没有将引用添加为项目,而是使用“添加引用”对话框中的“浏览”选项卡指向dllexe If you add reference using Projects tab you should go directly to the source code when you select Go To Definition. 如果使用“项目”选项卡添加引用,则在选择“转到定义”时应直接转到源代码。

Note: If you do not have project for the dll then you will get metadata only from dll 注意:如果您没有dll专案,那么您只会从dll取得metadata

If your definition you are going to find using F12 is in the same project, then it will show total definition of method/variable/class. 如果您要使用F12查找的定义在同一项目中,则它将显示方法/变量/类的总定义。

If your definition is outside the project i,e you are referencing different project, then it will show only declaration. 如果您的定义在项目之外,即您引用的是其他项目,那么它将仅显示声明。

如果尝试从编译的DLL中查看所引用方法的源代码,则不能,因为它是编译后的代码,因此不是源代码。

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

相关问题 当按F12进入Visual Studio 2015 / C#中的定义时出现错误 - I got error when press F12 Go to definition in Visual Studio 2015 / C# 如何通过单击F12在Visual Studio 2015中查看依赖项的源代码? - How to view source code of dependencies in Visual Studio 2015 by clicking F12? 如何隐藏<summary>在 Visual Studio 代码中按 F12(转到定义)时的 [元数据]</summary> - How to hide <summary> in [metadata] when press F12 (Go to definition) in visual studio code 使用C#获取Web的开发人员模式源代码(F12)(Web的动态源) - Get Developer Mode Source Code (F12) of a Web Page using C# (Dynamic Source of a web) Visual Studio转到定义(F12)打开对象浏览器而不是代码视图 - Visual Studio Go to Definition (F12) opens Object Browser instead of Code View Visual C# 在一天中的特定时间模拟 F12 按键 - Visual C# Simulating F12 keypress at certain time of day 如何从后面的c#asp.net应用程序代码写入chrome/ie/ff f12控制台 - How to write into chrome/ie/ff f12 console from c# asp.net application code behind VSCode C#“转到定义”(F12)不起作用 - VSCode C# "go to definition" (F12) not working VS2010 C#:如何在按F12键时查看内部​​类的定义? - VS2010 C#: How to view internal classes definitions when I press F12? Visual Studio Dom Explorer和IE F12工具Dom Explorer之间的区别 - Difference between Visual Studio Dom Explorer and I.E. F12 tools Dom Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM