2017-01-09 111 views
1

Visual Studio在构建时创建XML文档。我有一个我想应用于它的xml样式表(xslt)。我想将此行添加到生成的文件中:将xml样式表声明添加到Visual Studio生成的XML文档

<?xml-stylesheet type="text/xsl" href="Documentation.xsl"?> 

优选地,xslt声明将在构建时添加。有没有办法做到这一点?

+0

您可以在生成后命令中更改生成的xml文件,并添加此xslt引用标记 – Yaman

回答

0

我通过创建后期制作批处理脚本解决了这个问题。它使用fart.exe为我的XML添加一个xsl样式表声明。我在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% 

谢谢@Yaman指出我在正确的方向。