51

I'm working on a project where a c++/cli library is being used primarily from a c# application.

Is there any way to make the code comments in c++/cli visible to c# intellisence within visual studio?

Assuming there isn't, what would be the best way to document the c++/cli code to enable its easier use from c# (and within c++/cli of course)? What is you opinion on XML comments vs doxygen vs other tools (which)?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Hrvoje Prgeša
  • 2,051
  • 5
  • 21
  • 36

5 Answers5

57

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.

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
Zoinks
  • 810
  • 7
  • 4
  • Yeah, the trick is to copy the XML (and also PDB if you're wanting to debug) alongside the dll you are referencing. This will work in VS2005 too. – Jason Williams Jul 02 '09 at 20:55
  • 3
    Works in Visual Studio 2010 too. The only difference is that xml files have extension ".xdc" – fdermishin Apr 20 '11 at 20:42
  • 1
    Quite a lot of upvotes on this - Followed your recommendation (confirmed `xml` file is present and comments exist, however intellisense does not show comments. This is in VS2017. – Aaron Hudon Mar 30 '17 at 23:28
  • Any new information on VS2015-2017 Using .NET 4+? Cause answer is fully OK for 2008-2012 years, but 3.5 is deprecated long time ago... – Ruslan Makrenko Apr 12 '18 at 12:33
  • 1
    This worked for me using VS2019. – dOxxx Nov 03 '20 at 20:08
  • Worked like a charm in VS2019/.Net Framework 4.5, thanks! – n0ne Apr 27 '21 at 02:17
2

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.

Jason Williams
  • 56,972
  • 11
  • 108
  • 137
1

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()
*/
albert
  • 8,285
  • 3
  • 19
  • 32
Will Eddins
  • 13,628
  • 5
  • 51
  • 85
0

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.

maxwellb
  • 13,366
  • 2
  • 25
  • 35
0

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...

Thomas Hansen
  • 5,523
  • 1
  • 23
  • 28