在 Visual Studio 2010 C++ 中为 /// 生成 XML 文档注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4059773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:24:37  来源:igfitidea点击:

Generate XML documentation comments for /// in Visual Studio 2010 C++

c++xmlcomments

提问by user471571

I need comment my function prototype (written in C/C++) with summary, returns, param tags. How can I persuade Visual Studio to insert xml tags after three forward slashes like in C#? I found one solution. When I rename xx.h xx.cs in C++ project, I can use /// for generating xml comments (IntelliSense in xml comments works too). There must be a better way, mustn't there? It would kill me to write it manually. I'll grateful for every useful comment.

我需要用摘要、返回、参数标签注释我的函数原型(用 C/C++ 编写)。如何说服 Visual Studio 在 C# 中的三个正斜杠后插入 xml 标签?我找到了一种解决方案。当我在 C++ 项目中重命名 xx.h xx.cs 时,我可以使用 /// 来生成 xml 注释(xml 注释中的 IntelliSense 也可以)。一定有更好的方法,不是吗?手动编写它会杀了我。我会感谢每一个有用的评论。

/// <summary>
/// 
/// </summary>
/// <param name="aa"></param>
/// <returns></returns>
bool function1(TypeX aa);

采纳答案by Athari

This functionality isn't buit-in. You can try using Visual Studio add-ins. I haven't used Atomineer Utils Pro Documentationmyself, but it looks promising. It generates documentation comments and supports C++. It costs $10 though.

此功能不是内置的。您可以尝试使用Visual Studio 加载项。我自己没有使用过Atomineer Utils Pro 文档,但它看起来很有希望。它生成文档注释并支持 C++。不过要10美元。

回答by tcb

CppTripleSlashcreates xml doc comment stubs in c++ files when /// is typed, similar to what is available for c# in visual studio. This also has some basic intellisense for completing XML doc comments.

当键入 /// 时,CppTripleSlash在 c++ 文件中创建 xml doc 注释存根,类似于 Visual Studio 中 c# 可用的内容。这也有一些用于完成 XML 文档注释的基本智能感知。

回答by Daniel A.A. Pelsmaeker

GhostDocwill now insert XML comments for C++ elements. Just put the cursor on an element and press Ctrl+Shift+D.

GhostDoc现在将为 C++ 元素插入 XML 注释。只需将光标放在一个元素上,然后按Ctrl+ Shift+ D

GhostDoc has a free version for personal use that will already do this.

GhostDoc 有一个供个人使用的免费版本,已经可以做到这一点。

回答by Contango

For C++/CLI

对于 C++/CLI

These instructions work well for Visual Studio 2015 Update 2.

这些说明适用于Visual Studio 2015 Update 2.

First, turn XML documentation on. This generates a metadata file, which means that the comments will be visible externally, including C#.

首先,打开 XML 文档。这会生成一个元数据文件,这意味着注释将在外部可见,包括 C#。

enter image description here

在此处输入图片说明

Next, as per the answer from @tcb, install CppTripleSlash. Restart Visual Studio, and you should be good to go.

接下来,根据 的答案@tcb,安装CppTripleSlash。重新启动 Visual Studio,您应该就可以开始了。

回答by Florian

Have a look at this add-in: GhostDoc

看看这个插件: GhostDoc

回答by Jesse Chisholm

In Visual Studio 2010 C++, you can define macros to insert things for you.

在 Visual Studio 2010 C++ 中,您可以定义宏来为您插入内容。

Define a macro to insert the basic function header summary line.

定义一个宏来插入基本函数标题摘要行。

/// <summary> </summary>

Another for an empty param line, another for a returns line.

另一个用于空参数行,另一个用于返回行。

/// <param name=""> </param>

and

/// <returns> </returns>

That will cover most of your needs with just three macros. If you use them enough then add a macro for /// <remarks></remarks>and /// <exception name=""></exception>and <see cref=""/>and any you don't use enough to make a macro for you would need to enter manually.

只需三个宏即可满足您的大部分需求。如果您足够使用它们,则为/// <remarks></remarks>and/// <exception name=""></exception><see cref=""/>任何您没有足够使用它们的宏添加一个宏,因为您需要手动输入。

Yes, you will have to type the name of the parameter in manually. :) Macros can't do everything. :)

是的,您必须手动输入参数的名称。:) 宏不能做所有事情。:)

See: MSDN : VS2010 : How to Record Macros

请参阅:MSDN:VS2010:如何录制宏

See: MSDN : VS2010 : How to Run macros

请参阅:MSDN:VS2010:如何运行宏

UPDATE: I was unaware of these threads when I wrote this answer:

更新:当我写这个答案时,我不知道这些线程:

SO: Macros don't run in VS2010

SO:宏不能在 VS2010 中运行

MS: Macros broken in VS2010 by security fix Feb 2014(with a suggested workaround)

MS:2014 年 2 月安全修复程序在 VS2010 中破坏了宏(带有建议的解决方法)

回答by Christian St.

This applies to C++/CLI

这适用于 C++/CLI

Another way is to use ILSpyto convert C++/CLI code to C#. Then, in C#, you're able to write comments with IntelliSence support. Then just copy the comments into the C++/CLI project, compile and you're fine :-)

另一种方法是使用ILSpyC++/CLI 代码转换为 C#。然后,在 C# 中,您可以使用 IntelliSence 支持编写注释。然后只需将注释复制到 C++/CLI 项目中,编译即可:-)

Configure Visual Studio (2013) to use ILSpy

配置 Visual Studio (2013) 以使用 ILSpy

  1. Download the ILSpy binary
  2. Add a new tools entry in Visual Studio by opening "Tools / External Tools / Add".
  3. There enter the path to ILSpy.exefor Command, $(TargetPath)for Arguments and $(TargetDir)for Initial directory.
  4. Apply and close the window.
  5. (A new entry shows up in the Tools tab)
  6. Create a new empty C# project.
  1. 下载 ILSpy 二进制文件
  2. 通过打开“工具/外部工具/添加”在 Visual Studio 中添加一个新工具条目。
  3. 在那里输入ILSpy.exe命令、$(TargetPath)参数和$(TargetDir)初始目录的路径。
  4. 应用并关闭窗口。
  5. (工具选项卡中会显示一个新条目)
  6. 创建一个新的空 C# 项目。

Use it

用它

If you then open any file of the C++/CLIproject and activate the new entry in the Tools tab, a window (ILSpy) appears displaying your assembly converted to C# code. Copy that code to a file located in the C# project and write XML comments.

如果随后打开C++/CLI项目的任何文件并激活“工具”选项卡中的新条目,则会出现一个窗口 (ILSpy),显示已转换为 C# 代码的程序集。将该代码复制到位于 C# 项目中的文件并编写 XML 注释。

回答by Andrey Borisovich

This feature is finally coming to Visual Studio 2019 16.6 as native feature (along with auto generated headers and C++20 full support):

此功能终于作为本机功能出现在 Visual Studio 2019 16.6 中(以及自动生成的标头和 C++20 完全支持):

https://docs.microsoft.com/pl-pl/visualstudio/releases/2019/release-notes-preview

https://docs.microsoft.com/pl-pl/visualstudio/releases/2019/release-notes-preview

After so many years...

经过这么多年...