2

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?

1
  • You might alter the generated xml file in a post-build command, and add this xslt reference tag Commented Jan 9, 2017 at 22:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.