框架 goto 定义显示注释,这些注释是从 xml 注释生成的吗?

发布于 2024-07-08 19:33:52 字数 313 浏览 6 评论 0原文

最近,我有点惊讶地发现我精心制作的 xml 注释没有出现在同事的智能感知中。 由于一直使用关联的程序集和项目引用,我没有意识到您还必须导出 .xml 文档才能访问此信息。

这让我想知道 .Net 框架智能感知是如何工作的。 如果我理解正确的话,.xml 文件必须隐藏在特殊文件夹中的某个位置吗?

但我的主要问题是关于“转到定义” - 如果您转到 .Net 框架程序集上的定义,您会获得从元数据生成的信息 - 而且还有大量有用的注释 - 这些是从 Xml 注释神奇地生成的,还是有人有编写一个宏+来转换它们只是为了构建? 换句话说:如何为我的程序集获得这种效果?

I was mildly surprised recently to discover that my carefully crafted xml comments weren't showing up in intellisense for my colleagues. Having always used the associated assemblies with project references, I hadn't realised that you had to export the .xml document as well to access this information.

This led me to wondering how the .Net framework intellisense works. If I understand correctly, the .xml files must be hidden away somewhere in a special folder?

But my main question is about 'Goto definition' - if you goto definition on a .Net framework assembly, you get the info generated from metadata - but also with plenty of helpful comments - are these magically generated from Xml comments, or did someone have to write a macro + to convert them just for the build? Putting it differently: how can I get this effect for my assemblies?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亚希 2024-07-15 19:33:52

您的项目是否配置为生成 XML 文档? 仅仅因为您将注释添加到源代码中,除非被告知,否则编译器不会生成 .xml 文件。

在项目属性页面中,转到“构建”选项卡并查看“输出”部分。 您应该看到一个标题为“XML 文档文件”的复选框条目。 如果该复选框后面的文本框为空,则不会生成 XML 文档文件。

生成 XML 文档文件后,您应该会在 IntelliSense 工具提示中看到您的注释。 如果您将对其他项目的引用包含为项目引用,那么这应该会自动发生。 如果包含对程序集的引用,则需要确保 xml 文件与引用的程序集位于同一位置。 (构建时,您应该获取所有程序集的 xml 文件,这些程序集分别位于 bin/debug 或 bin/release 文件夹中。)

对于 .NET Framework 程序集本身,相应的 xml 文档文件作为框架。 对于 .NET 2.0、3.0 或 3.5,文档文件位于 C:\Windows\Microsoft.NET\Framework\v2.0.50727\en(假设默认安装 Framework)。 Visual Studio 中的 IntelliSense 工具提示和“转到定义”功能都使用这些文件来显示此信息。 没有发生任何特殊处理或运行宏来实现这一点。 Visual Studio 最有可能使用的唯一信息是注册表项的组合,以确定文档文件的正确路径。

虽然您可能可以在同一文件夹中找到您自己的程序集的 xml 文档文件,但我建议不要这样做,因为您随后会使用非框架相关文件污染框架安装。

Are your projects configured to generate the XML documentation? Just because you add the comments to the source code, the compiler won't generate the .xml file unless it's told to.

In the project properties page, go to the "Build" tab and look at the "Output" section. You should see a checkbox entry titled "XML documentation file". If textbox following that checkbox is empty you aren't generating the XML documentation file.

Once you get the XML documentation file generated, you should see your comments in the IntelliSense tooltips. If you include references to other projects as a project reference this should happen automatically. If you include references to assemblies, you need to ensure that the xml file is in the same location as the referenced assembly. (When you build, you should get xml files for all of the assemblies that have them in the bin/debug or bin/release folder respectively.)

For the .NET Framework assemblies themselves, the corresponding xml documentation files are installed as part of the Framework. For .NET 2.0, 3.0, or 3.5 the documentation files are located at C:\Windows\Microsoft.NET\Framework\v2.0.50727\en (assuming a default installation of the Framework). These files are used by both the IntelliSense tooltips and the "Go to Definition" functionality in Visual Studio in order to display this information. There is not any special processing that takes place or macros run in order to make this happen. The only information Visual Studio most likely uses is a combination of registry keys to determine the correct path to the documentation files.

While you probably could locate the xml documentation files for your own assemblies in the same folder, I would recommend against doing so as you then pollute the Framework installation with non-Framework related files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文