在Visual Studio 2010 c++中生成XML文档注释。

时间:2023-01-14 19:07:14

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在三个前斜杠之后插入xml标记,比如c# ?我发现一个解决方案。当我重命名xx。h xx。c++项目中的cs,我可以使用///来生成xml注释(xml注释中的IntelliSense也可以工作)。一定有更好的办法,是不是?如果我用手工写的话,我会死的。我将感激每一个有用的评论。

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

7 个解决方案

#1


7  

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

st通道内置这个功能并不是。您可以尝试使用Visual Studio插件。我自己还没有使用Atomineer Utils专业文档,但是看起来很有希望。它生成文档注释并支持c++。虽然花费10美元。

#2


8  

CppTripleSlash creates 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文档注释也有一些基本的智能感知。

#3


6  

GhostDoc will 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有一个供个人使用的免费版本,已经可以这样做了。

#4


2  

For C++/CLI

These instructions work well for Visual Studio 2015 Update 2.

这些说明对Visual Studio 2015更新2很有效。

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

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

在Visual Studio 2010 c++中生成XML文档注释。

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

接下来,按照@tcb的回答,安装cpptriplesrush。重新启动Visual Studio,你应该很好。

#5


1  

Have a look at this add-in: GhostDoc

看看这个插件:GhostDoc

#6


0  

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.

这将用三个宏来满足您的大部分需求。如果您足够使用它们,那么为/// < comments >添加一个宏; 和/// 以及任何您没有使用足够的宏来创建一个宏,您需要手动输入。

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

所以:宏不会在VS2010中运行

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

MS:在VS2010中被安全修复的宏在2014年2月(有建议的解决方案)

#7


0  

This applies to C++/CLI

Another way is to use ILSpy to 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 :-)

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

Configure Visual Studio (2013) to use ILSpy

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

Use it

If you then open any file of the C++/CLI project 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项目的任何文件并激活Tools选项卡中的新条目,将出现一个窗口(ILSpy),显示转换为c#代码的程序集。将该代码复制到c#项目中的文件中,并编写XML注释。

#1


7  

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

st通道内置这个功能并不是。您可以尝试使用Visual Studio插件。我自己还没有使用Atomineer Utils专业文档,但是看起来很有希望。它生成文档注释并支持c++。虽然花费10美元。

#2


8  

CppTripleSlash creates 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文档注释也有一些基本的智能感知。

#3


6  

GhostDoc will 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有一个供个人使用的免费版本,已经可以这样做了。

#4


2  

For C++/CLI

These instructions work well for Visual Studio 2015 Update 2.

这些说明对Visual Studio 2015更新2很有效。

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

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

在Visual Studio 2010 c++中生成XML文档注释。

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

接下来,按照@tcb的回答,安装cpptriplesrush。重新启动Visual Studio,你应该很好。

#5


1  

Have a look at this add-in: GhostDoc

看看这个插件:GhostDoc

#6


0  

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.

这将用三个宏来满足您的大部分需求。如果您足够使用它们,那么为/// < comments >添加一个宏; 和/// 以及任何您没有使用足够的宏来创建一个宏,您需要手动输入。

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

所以:宏不会在VS2010中运行

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

MS:在VS2010中被安全修复的宏在2014年2月(有建议的解决方案)

#7


0  

This applies to C++/CLI

Another way is to use ILSpy to 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 :-)

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

Configure Visual Studio (2013) to use ILSpy

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

Use it

If you then open any file of the C++/CLI project 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项目的任何文件并激活Tools选项卡中的新条目,将出现一个窗口(ILSpy),显示转换为c#代码的程序集。将该代码复制到c#项目中的文件中,并编写XML注释。