27

Java developers can easily generate HTML documentation from their Java code, which is a convenient way to post APIs online. This is an example.

Is there a similar tool for C# code?

It must be free, ideally open source.

Must run on Windows and Linux, at least.

HTML frames are not needed, tools that generate just one long HTML page are perfect too.

14

You can do this with the normal Microsoft C# compiler. Though it isn't open source. Debately it is free, since it uses tools you already have.

For C# file called XMLsample.cs

csc XMLsample.cs /doc:XMLsample.xml

will produce xml file XMLsample.xml. By applying a style-sheet to this, you'll have nice website. CSS should do, though for more significant reformating you might need to use XSLT.

see MSDN


It is also available on the Mono C# compiler. Mono C# is free and open source.

mcs XMLsample.cs /doc:XMLsample.xml

See Mono manpage

  • This can not generate the documentation of a C# file with no Main() method. Is there any other command for it? – Riky Sep 7 '17 at 9:55
  • @Riky questions on the use of software are better suited to superuser, or in this case stackoverflow – Lyndon White Feb 23 '18 at 3:12
14

Doxygen seems like what would work for you.

  • It can generate an on-line documentation browser (in HTML) and/or an off-line reference manual (in $\mbox{\LaTeX}$) from a set of documented source files.
  • There is also support for generating output in RTF (MS-Word), PostScript, hyperlinked PDF, compressed HTML, and Unix man pages.
  • The documentation is extracted directly from the sources, which makes it much easier to keep the documentation consistent with the source code.

It can be used to generate documentation from C#, along with other languages like C, Objective-C, PHP, Java, Python.

  • I've just tried Doxygen, it works like a charm, thank you very much! – Luke 4 hours ago
5

Putting in my 2c because I was following the accepted answer, but it turns out,

Microsoft C# compiler is only doing a half-baked job. I.e., it only gives you an xml file. But to have a nice website, you'll still have to apply some style-sheet to it, and that's where the bridge is broken -- Microsoft C# compiler doesn't do that, and the Microsoft supported tools that does that, the Sandcastle CodePlex project, is no longer under active development by Microsoft.

All in all, the accepted answer maybe good for year 2014, but no longer good for 2017.

The new answer is Eric Woodruff’s Sandcastle Help File Builder site at https://GitHub.com/EWSoftware/SHFB, which is forked and based on the existing Sandcastle source code.

2

We use Document! X and it works really well for us. You get the full API docs from the comments and the style sheets for it make it look very very nice. They're also really responsive on support.

With that said, it's not free. But for what it delivers, I think it's well worth it. (We previously used a free program, not doxygen, and that ended up being too expensive in terms of how much time it took.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.