Visual Studio creates XML documentation at build-time. I have an xml-stylesheet (xslt) that I would like to apply to it. I would like to add this line to the generated file:
<?xml-stylesheet type="text/xsl" href="Documentation.xsl"?>
Preferably, the xslt declaration would be added at build-time. Is there a way to do this?
I solved this by creating a post-build batch script. It uses fart.exe to add an xsl stylesheet declaration to my XML. I added it as a post-build step in my Visual Studio project.
::Postbuild script.
::Adds xsl stylesheet to XML documentation
::%1 is the project directory string
::Only add a stylesheet if it's not already there
findstr /m "xml-stylesheet" %1Documentation\MCM.XML
if %errorlevel%==1 (
::Use "Find and Replace Text" (fart.exe) to add xml-stylesheet declaration
"%1Documentation/fart.exe" -C -q "%1Documentation\MCM.XML" "<\?xml version=\"1.0\"\?>" "<\?xml version=\"1.0\"\?><\?xml-stylesheet type=\"text/xsl\" href=\"Documentation.xsl\"\?>"
if %errorlevel%==9009 (
echo .
) else (
if ERRORLEVEL 1 CMD /C EXIT 0
)
) else (
cmd /C EXIT 0
)
exit %errorlevel%
Thanks @Yaman for pointing me in the right direction.