简体   繁体   中英

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

I'm the new of c# and visual studio. when I use the F12 to go to definition, but sometime it didn't work. 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. 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.

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).
  2. If you don't have ReSharper, you can use the free JetBrains dotPeek product, although that's not integrated into 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. This is the best experience.
  4. If possible, get your hands on some matching pdb files. 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. 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

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.

If your definition is outside the project i,e you are referencing different project, then it will show only declaration.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM