简体   繁体   English

将xml-stylesheet声明添加到Visual Studio生成的XML文档中

[英]Adding xml-stylesheet declaration to Visual Studio generated XML documentation

Visual Studio creates XML documentation at build-time. Visual Studio在构建时创建XML文档。 I have an xml-stylesheet (xslt) that I would like to apply to it. 我有一个xml-stylesheet(xslt),我想申请它。 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. 优选地,xslt声明将在构建时添加。 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. 它使用fart.exe将xsl样式表声明添加到我的XML中。 I added it as a post-build step in my Visual Studio project. 我在Visual Studio项目中将其添加为后期构建步骤。

::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. 谢谢@Yaman指出我正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM