繁体   English   中英

从安装程序更新第三方的.config转换

[英]update 3rd party's .config transformation's from installer

我有2个必须配置的.config文件。 一个是web.config ,一个是app.config ,这两个文件均来自我们的代码在其中运行的第三方供应商。 因此,我们需要对其进行调整,以便它可以看到我们的代码。

我的计划是使用xslt提取我们的.config文件并将其合并到第三方。

我已经看到了一些有关如何使用msbuild进行此类操作的示例,但是由于我们是在现场进行的,因此我们将不得不使用安装程序来进行处理。 任何帮助,将不胜感激。

示例:我们首先开始:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <gcServer enabled="true"/>
  </runtime>
</configuration>

自定义部分

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="productName" type="company.productName, company, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" />
  </configSections>
  <productName defaultProvider="Provider1">
    <providers>
      <clear />
      <add name="Provider1" type="Company.Product.Authentication.Provider1, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="localhost:5555" />
      <add name="Provider2" type="Company.Product.Authentication.Provider2, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="demo.example.com" />
    </providers>
  </productName>
</configuration>

最后是:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="productName" type="company.productName, company, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" />
  </configSections>
  <productName defaultProvider="Provider1">
    <providers>
      <clear />
      <add name="Provider1" type="Company.Product.Authentication.Provider1, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="localhost:5555" />
      <add name="Provider2" type="Company.Product.Authentication.Provider2, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="demo.example.com" />
    </providers>
  </productName>
  <runtime>
    <gcServer enabled="true"/>
  </runtime>
</configuration>

此样式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:apply-templates select="document('test.xml')/*">
            <xsl:with-param name="pContext" select="*"/>
        </xsl:apply-templates>
    </xsl:template>
    <xsl:template match="*[*]">
        <xsl:param name="pContext" select="/.."/>
        <xsl:variable name="vCurrent" select="."/>
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:copy-of select="$pContext/@*"/>
            <xsl:for-each select="*">
                <xsl:apply-templates select=".">
                    <xsl:with-param name="pContext"
                         select="$pContext/*[name()=name(current())]"/>
                </xsl:apply-templates>
            </xsl:for-each>
            <xsl:for-each select="$pContext/*">
                <xsl:apply-templates
                     select="(.)[not($vCurrent/*[name()=name(current())])]"/>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*[not(*)]">
        <xsl:param name="pContext" select="/.."/>
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:copy-of select="$pContext/@*"/>
            <xsl:apply-templates
                 select="node()[not($pContext)]|$pContext/node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

使用此输入:

<configuration>
    <runtime>
        <gcServer enabled="true"/>
    </runtime>
</configuration>

而这个test.xml

<configuration>
    <configSections>
        <section name="productName" type="company.productName, company, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" />
    </configSections>
    <productName defaultProvider="Provider1">
        <providers>
            <clear />
            <add name="Provider1" type="Company.Product.Authentication.Provider1, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="localhost:5555" />
            <add name="Provider2" type="Company.Product.Authentication.Provider2, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="demo.example.com" />
        </providers>
    </productName>
</configuration>

输出:

<configuration>
    <configSections>
        <section name="productName" type="company.productName, company, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c"></section>
    </configSections>
    <productName defaultProvider="Provider1">
        <providers>
            <clear></clear>
            <add name="Provider1" type="Company.Product.Authentication.Provider1, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="localhost:5555"></add>
            <add name="Provider2" type="Company.Product.Authentication.Provider2, Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d9072a6c5128d57c" hostName="demo.example.com"></add>
        </providers>
    </productName>
    <runtime>
        <gcServer enabled="true"></gcServer>
    </runtime>
</configuration>

注意 :三个规则。 文档根规则:将遍历树更改为需要更新的源,并将输入源保留为$pContext 具有子元素元素的规则:使用属性复制自身,使用$pContext的属性更新属性(这是由处理器完成的,因为创建了属性规则 ),将模板应用于具有新$pContext元素子元素(具有$pContext的旧$pContext的子元素)相同的名称),将模板应用于$pContext的子项(不匹配任何子项的名称)。 没有孩子的元素规则元素:自我复制与更新的属性$pContext属性,如果在一个节点$pContext复制,从而取代元素含量(或者,如果你有一个空的元素,甚至剥离$pContext )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM