要自动将某些组件集成到现有网站中,我必须更新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,oldVersion和newVersion:
转换:
<?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>
结果:
<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>
版本没有被替换。
答案 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>