将 xml-样式表声明添加到 Visual Studio 生成的 XML 文档

Adding xml-stylesheet declaration to Visual Studio generated XML documentation

Visual Studio 在构建时创建 XML 文档。我有一个 xml-stylesheet (xslt),我想将其应用于它。我想将这一行添加到生成的文件中:

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

最好在构建时添加 xslt 声明。有办法吗?

我通过创建 post-build 批处理脚本解决了这个问题。它使用 fart.exe 将 xsl 样式表声明添加到我的 XML。我将其作为 post-build 步骤添加到我的 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 为我指明了正确的方向。