Get class source code instead of Metadata in Visua

2019-06-28 03:29发布

问题:

Sometimes when I am working away on a project, I will hit my button for 'go to definition' (F12 is the default I think) on a class or method or whatever. Great! This works like a dream expect for cases where I have code that is built into an assembly. In these cases the 'definition' is contained in a generated '[from metadata]' file. Of course this makes sense, especially for 3rd party stuff, but what about cases where I know where the source code is located? Is there a way I can Visual Studio to put in the extra effort to navigate to the code? Is there a macro or something out there that can do this? Am I doomed?

p.s.
I know that Resharper and similar tools can probably do this, but I don't have them so let's just rule those type of answers out now.

回答1:

The bottom line is that you can't view source code using "Go to definition" for classes which are included in your project via file references (typically, third-party assemblies). For classes which are included via project references, you will be able to view the code in this way. All "Go to definition" does is try to locate the code file for the type in your project or a referenced project. If you don't have the code file available (which would be the case for third-party assemblies), it won't be able to show it and gives you the definition generated from the type metadata.

If you know where the source code is located, you could possibly do this using a macro of some sort or just include it as a project reference rather than a file reference.