记录 C++/CLI 库代码以供 C# 使用 - 最佳工具和实践?

发布于 2024-07-25 07:53:29 字数 1433 浏览 5 评论 0 原文

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

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

发布评论

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

评论(5

隐诗 2024-08-01 07:53:29

我已经让它按如下方式工作:

  1. 对 C++/CLI 标头条目使用 XML 样式注释。 这意味着需要完整的 XML 注释(三斜杠注释,至少

    标记)

  2. 确保 C++ 编译器选项 生成 XML 文档文件 已启用。 这应该生成一个 XML 文件,其中包含与程序集同名的文档 (MyDll.xml)。

  3. 确保 C# 项目引用程序集 MyDll.dll,其中 MyDll.xml 也存在于同一文件夹中。 当您将鼠标悬停在程序集中的引用上时,MS Visual Studio 将加载文档。

这在 Visual Studio 2008 中为 .NET 3.5 构建的程序集上对我有用。

I have gotten it to work as follows:

  1. Use XML style comments for your C++/CLI header entries. This means the full XML comment is required (triple-slash comments, <summary> tag at a minimum)

  2. Make sure that the C++ compiler option Generate XML Documentation Files is on. This should generate an XML file with documentation with the same name as your assembly (MyDll.xml).

  3. Make sure that the C# project references your assembly MyDll.dll where MyDll.xml is also present in the same folder. When you mouse over a reference from the assembly, MS Visual Studio will load the documentation.

This worked for me in Visual Studio 2008 on an assembly built for .NET 3.5.

陌生 2024-08-01 07:53:29

DocXml 的主要优点是受 VS 支持(语法着色、智能感知、自动导出到 XML 文件)。 Doxygen 工具可以读取 DocXml 格式,因此您仍然可以将它们与此格式一起使用。

为了帮助您以最小的努力生成整洁、准确的文档注释,您可能想查看我的插件 AtomineerUtils。 这消除了创建和更新 DocXml、Doxygen、JavaDoc 或 Qt 格式注释的大部分工作,并且它支持 C、C++、C++/CLI、C#、Java、JavaScript、TypeScript、JScript、UnrealScript、PHP 和 Visual Basic 代码。

DocXml has the major advantage of being supported by VS (syntax colouring, intellisense, automatic export to the XML files). The Doxygen tools can read DocXml format so you can still use them with this format too.

To help you generate tidy and accurate Doc comments with a minimum of effort, you might like to check out my addin AtomineerUtils. This takes most of the work out of creating and updating DocXml, Doxygen, JavaDoc or Qt format comments, and it supports C, C++, C++/CLI, C#, Java, JavaScript, TypeScript, JScript, UnrealScript, PHP and Visual Basic code.

醉态萌生 2024-08-01 07:53:29

查看 Doxygen 可能会给您带来很多价值。 然后查找 Doxygen.NET - 这是我们为自己使用而编写的东西,它根据 Doxygen 的 XML 文件输出构建“对象层次结构”...

You'll probably have a lot of value taking a look at Doxygen. And then look up Doxygen.NET - which is something we wrote for our own use which builds "Object Hierarchies" from the XML file outputs from Doxygen...

南城旧梦 2024-08-01 07:53:29

有趣的。 尝试了多种方法后,托管 C++ 项目和 C# 之间的智能感知似乎不起作用。

以下示例将在声明它的 C++ 环境中为您提供正确的智能感知,但在 C# 中引用该对象不会显示任何内容:

// Gets the value of my ID for the object, which is always 14.
public: virtual property int MyId
{
    int get() { return 14; } 
}

XML 注释也不起作用。 我猜这要么是一个错误,要么需要一些我无法弄清楚的东西。 从这个问题缺乏答案来看,也许是一个错误。

就文档生成而言,我建议采用 XML 文档路径。 Doxygen 支持读取 XML 文档,这与 C# 的标准 XML 文档基本相同。 它确实倾向于为标签的开头和结尾添加额外的行,但在我看来比以下 doxygen 替代方案更具可读性:

//! A normal member taking two arguments and returning an integer value.
/*!
  \param a an integer argument.
  \param s a constant character pointer.
  \return The test results
  \sa Test(), ~Test(), testMeToo() and publicVar()
*/

Interesting. After trying several methods, it's looking like the intellisense between a Managed C++ project and C# doesn't work.

The following example will give you proper intellisense in the C++ environment where it is declared, but referencing the object in C# shows nothing:

// Gets the value of my ID for the object, which is always 14.
public: virtual property int MyId
{
    int get() { return 14; } 
}

XML comments don't work either. I would guess that this is either a bug, or requires something I can't figure out. Judging from the lack of answers on this question, perhaps a bug.

As far as documentation generation, I'd recommend going the path of XML documentation. Doxygen supports reading XML documentation which is mostly identical to the standard XML documentation for C#. It does tend to add extra lines just for tag openings and closings, but is much more readable in my opinion than the following doxygen alternative:

//! A normal member taking two arguments and returning an integer value.
/*!
  \param a an integer argument.
  \param s a constant character pointer.
  \return The test results
  \sa Test(), ~Test(), testMeToo() and publicVar()
*/
故事灯 2024-08-01 07:53:29

你是对的。 这不起作用。 C++ 构建会将其 IntelliSense 信息添加到主 .ncb 文件中,您将获得方法名称的自动完成等。但是,您是正确的,因为您将无法获得有关每个方法的“注释”描述等。

You are right. It doesn't work. The C++ build will add its IntelliSense information into the master .ncb file, and you will get the autocompletion of method names, etc. However, you are correct in that you will be unable to get the "comment" description about each method, etc.

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