"code" tag pointed to external code file

Topics: User Forum
Sep 26, 2011 at 10:54 PM



Hopefully this hasn't been posted before. I searched around a bit, but didn't find anything similar.

I include quite a few C# and VB.Net code samples in my documentation using the "code" tag. Right now, I have a separate project where I write these samples and run them to make sure they compile and work. When I finish, I manually copy the code into the documentation and hand-edit it to include "///" before each line, etc.

This is fairly laborious, and when I need to update my samples, I have to either start the whole process over again, or hand edit the code in the comments and risk generating samples that don't work.

Is there any way to use a link to an external code file (or unit test, etc.) instead of including it inline? That way I could write a sample app to include in my project, and be certain that the latest versions of the samples are always copied to the documentation every time I build.



Sep 27, 2011 at 1:25 AM

See the documentation for the Code Block component.  It describes the extension attributes available on the <code> element to allow importing whole code files or specific regions.  The code block component is included by default so you don't have to add it to the project unless you want to override its default behavior.



Sep 27, 2011 at 1:49 PM

Thanks, Eric. That is exactly what I was looking for.