在 Visual Studio 中获取类源代码而不是元数据
有时,当我忙于一个项目时,我会在类或方法或其他内容上点击“转到定义”按钮(我认为 F12 是默认按钮)。伟大的!对于我将代码内置到程序集中的情况来说,这就像梦想一样。在这些情况下,“定义”包含在生成的“[来自元数据]”文件中。当然这是有道理的,特别是对于第 3 方的东西,但是如果我知道源代码位于哪里呢?有没有办法让 Visual Studio 付出额外的努力来导航到代码?有没有宏或其他东西可以做到这一点?我注定了吗?
附:
我知道 Resharper 和类似的工具可能可以做到这一点,但我没有它们,所以现在让我们排除这些类型的答案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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.