【问题标题】:XPath matching and get text valueXPath 匹配并获取文本值
【发布时间】:2018-02-21 13:44:13
【问题描述】:

我目前在将我的项目转移到持续集成中遇到问题。

我放置了一个 parameters.xml 文件,该文件应该通过 getParameter 文件覆盖解决方案的 web.config 文件的值。

但在整个配置中,我有两个设置由于其特殊情况而在部署后未更新。

确实,我尝试访问文本而不是属性。 所以我有这个:

...<property name="connection.connection_string">Server=XXX\DEV;initial catalog=YYY;Integrated Security=ZZZ</property>...

并尝试用这个进行匹配和替换,但参数在部署后没有更新

  <parameter
    name="nhibernate connection string"
    description="Please provide the nhibernate connection string."
    defaultValue="Server=XXX\DEV;initial catalog=YYY;Integrated Security=ZZZ">
    <parameterEntry kind="XmlFile" scope="\\web.config$" match="/AAA/BBB/CCC/property[@name='connection.connection_string']/text()" />
  </parameter>

在我有的 SetParameters 文件中

  <setParameter name="nhibernate connection string" value="Server=SSS\DD;initial catalog=XXX;Integrated Security=ZZZ" />

感谢您的帮助!

【问题讨论】:

    标签: c# xml xpath continuous-integration


    【解决方案1】:

    假设您正在谈论 Web 部署参数。在您的 web.config 中,您有一个 ...&lt;property name="connection.connection_string"&gt;... 元素,其值需要在部署期间由 setParameter 更改。

    我看到的一个问题是参数条目中scope 的值。它应该是一个正则表达式。所以为了匹配 web.config,. 应该像\\web\.config$ 一样被转义。此外,web.config 的路径应该是它在包 .zip 文件中的位置。您可能需要仔细检查路径是否与表达式匹配。

    XPath 对我来说似乎很好。但是您可能需要使用一些工具来验证它是否按预期工作,或者不符合您的 web.config。有很多在线工具可以做到这一点,比如这个:http://chris.photobooks.com/xml/default.htm

    附带说明,如果您只是在 web.config 中有一些针对不同环境的设置,web.config transformation 将是比 Web Deploy 更容易和更好的方式来实现 CI/CD。

    【讨论】:

      猜你喜欢
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      相关资源
      最近更新 更多