Framework goto definition shows comments, are these generated from xml comments?

ぐ巨炮叔叔 提交于 2019-12-10 11:47:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/277459/framework-goto-definition-shows-comments-are-these-generated-from-xml-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!