Xml 更新web.config

Xml 更新web.config,xml,xslt,web-config,Xml,Xslt,Web Config,要在现有网站中自动集成一些组件,我必须更新web.config文件和程序集信息 目前我有: <configuration> <!-- register local configuration handlers --> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privateP

要在现有网站中自动集成一些组件,我必须更新web.config文件和程序集信息

目前我有:

<configuration>
    <!-- register local configuration handlers -->
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="bin;bin\HttpModules;bin\Providers;bin\Modules;bin\Support;"/>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

这些组件需要新的publicKeyToken、旧版本和新版本:

  • Json
  • System.Web.Mvc
转型:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:asm="urn:schemas-microsoft-com:asm.v1">
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//asm:dependentAssembly[asm:assemblyIdentity/@name='System.Web.Mvc']">
        <xsl:copy>
          <xsl:attribute name="Only4test">VOID</xsl:attribute>
          <xsl:attribute name="assemblyIdentity/publicKeyToken">31bf3856ad364e35</xsl:attribute>
          <xsl:attribute name="bindingRedirect/oldVersion">0.0.0.0-5.2.3.0</xsl:attribute>
          <xsl:attribute name="bindingRedirect/newVersion">5.2.3.0</xsl:attribute>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//asm:dependentAssembly[asm:assemblyIdentity/@name='Newtonsoft.Json']">
        <xsl:copy>
          <xsl:attribute name="Only4test">VOID</xsl:attribute>
          <xsl:attribute name="assemblyIdentity/publicKeyToken">30ad4fe6b2a6aeed</xsl:attribute>
          <xsl:attribute name="bindingRedirect/oldVersion">0.0.0.0-6.0.0.0</xsl:attribute>
          <xsl:attribute name="bindingRedirect/newVersion">6.0.0.0</xsl:attribute>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:transform>

无效的
31bf3856ad364e35
0.0.0.0-5.2.3.0
5.2.3.0
无效的
30AD4Fe6B2A6EED
0.0.0.0-6.0.0.0
6.0.0.0
导致:

<configuration>
    <!-- register local configuration handlers -->
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="bin;bin\HttpModules;bin\Providers;bin\Modules;bin\Support;"/>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
            </dependentAssembly>
            <dependentAssembly Only4test="VOID">
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0"/>
            </dependentAssembly>
            <dependentAssembly Only4test="VOID">
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>


版本没有被替换

你可以试试这个

    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:asm="urn:schemas-microsoft-com:asm.v1">
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//asm:dependentAssembly[asm:assemblyIdentity/@name='System.Web.Mvc']">
        <xsl:copy>
            <xsl:attribute name="Only4test">VOID</xsl:attribute>
            <xsl:if test="@publicKeyToken">
                <xsl:attribute name="{local-name()}">31bf3856ad364e35</xsl:attribute>
            </xsl:if>
            <xsl:if test="@oldVersion">
                <xsl:attribute name="{local-name()}">0.0.0.0-5.2.3.0</xsl:attribute>
            </xsl:if>
            <xsl:if test="@newVersion">
                <xsl:attribute name="{local-name()}">5.2.3.0</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//asm:dependentAssembly[asm:assemblyIdentity/@name='Newtonsoft.Json']">
        <xsl:copy>
            <xsl:attribute name="Only4test">VOID</xsl:attribute>
            <xsl:if test="@publicKeyToken">
                <xsl:attribute name="{local-name()}">30ad4fe6b2a6aeed</xsl:attribute>
            </xsl:if>
            <xsl:if test="@oldVersion">
                <xsl:attribute name="{local-name()}">0.0.0.0-6.0.0.0</xsl:attribute>
            </xsl:if>
            <xsl:if test="@newVersion">
                <xsl:attribute name="{local-name()}">6.0.0.0</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:transform>

无效的
31bf3856ad364e35
0.0.0.0-5.2.3.0
5.2.3.0
无效的
30AD4Fe6B2A6EED
0.0.0.0-6.0.0.0
6.0.0.0

您可以试试这个

    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:asm="urn:schemas-microsoft-com:asm.v1">
    <xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//asm:dependentAssembly[asm:assemblyIdentity/@name='System.Web.Mvc']">
        <xsl:copy>
            <xsl:attribute name="Only4test">VOID</xsl:attribute>
            <xsl:if test="@publicKeyToken">
                <xsl:attribute name="{local-name()}">31bf3856ad364e35</xsl:attribute>
            </xsl:if>
            <xsl:if test="@oldVersion">
                <xsl:attribute name="{local-name()}">0.0.0.0-5.2.3.0</xsl:attribute>
            </xsl:if>
            <xsl:if test="@newVersion">
                <xsl:attribute name="{local-name()}">5.2.3.0</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//asm:dependentAssembly[asm:assemblyIdentity/@name='Newtonsoft.Json']">
        <xsl:copy>
            <xsl:attribute name="Only4test">VOID</xsl:attribute>
            <xsl:if test="@publicKeyToken">
                <xsl:attribute name="{local-name()}">30ad4fe6b2a6aeed</xsl:attribute>
            </xsl:if>
            <xsl:if test="@oldVersion">
                <xsl:attribute name="{local-name()}">0.0.0.0-6.0.0.0</xsl:attribute>
            </xsl:if>
            <xsl:if test="@newVersion">
                <xsl:attribute name="{local-name()}">6.0.0.0</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:transform>

无效的
31bf3856ad364e35
0.0.0.0-5.2.3.0
5.2.3.0
无效的
30AD4Fe6B2A6EED
0.0.0.0-6.0.0.0
6.0.0.0