因为我的实际转换相对简单的我开发了这个XSL转换:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="xformPath">web.Prod.config</xsl:variable>
<xsl:variable name="xform" select="document($xformPath)"></xsl:variable>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template name="output-transform">
<xsl:param name="xformNode" />
<xsl:variable name="key" select="@key" />
<xsl:choose>
<xsl:when test="$xformNode">
<xsl:copy-of select="$xformNode" />
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/configuration/appSettings/add">
<xsl:variable name="key" select="@key" />
<xsl:call-template name="output-transform">
<xsl:with-param name="xformNode" select="$xform/configuration/appSettings/add[@key=$key]" />
</xsl:call-template>
</xsl:template>
<xsl:template match="/configuration/connectionStrings/add">
<xsl:variable name="name" select="@name" />
<xsl:call-template name="output-transform">
<xsl:with-param name="xformNode" select="$xform/configuration/connectionStrings/add[@name=$name]" />
</xsl:call-template>
</xsl:template>
<xsl:template match="/configuration/system.web/customErrors">
<xsl:call-template name="output-transform">
<xsl:with-param name="xformNode" select="$xform/configuration/system.web/customErrors" />
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
这具有一些明显的缺点,
- 项目要更换必须手动定义
- 替换整个元素,不仅指定的属性
- 不维护儿童元素(例如我试图改变
system.web/[email protected]
到false
但我失去了我所有的system.web/compilation/assemblies
项)
我计划增加这一个命令行一步,我的Visual Studio生成步骤和复制文件的步骤之间,并呼吁无论是MSXSL.EXE或撒克逊的HE变换引擎。
您应该将项目更改为Web应用程序以获得更多功能以及应用程序的稳定性和一致性。 –
CeCe的解决方案是否能解决您的问题? –
我不认为它会,因为它需要一个额外的基本文件(导致在开发过程中使用的web.config在构建过程中不被引用),或者它需要将令牌存储在web.config中文件本身,在开发过程中渲染web.config是无用的,除非只添加了本地后构建步骤,也可以在本地执行替换令牌(如果我正确理解插件)。 – mlhDev