转换web配置以外的文件替换元素

时间:2017-09-27 09:02:49

标签: xml xdt-transform

我有一个NLog.config,我必须指向另一个生产数据库。 我正在使用this  改造它的工具。 这是我的NLog.Config的一部分。

<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets>
  <target name="ExceptionLog" type="Database">
    <connectionString>
       ---- Db Connection string for test-------
    </connectionString>

我已经创建了生成转换但是无法转换文件。

这就是我所拥有的

<?xml version="1.0"?>
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <parameters value="Db connection for prod"
           xdt:Transform="Replace"  xdt:Locator="XPath(targets/target/connectionString)"  />
</configuration>

我们需要更改整个元素而不是属性。

1 个答案:

答案 0 :(得分:1)

成功添加&#34; nlog&#34; xdt名称空间别名:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" 
               xmlns:nlog="http://www.nlog-project.org/schemas/NLog.xsd">

  <nlog:connectionString xdt:Transform="Replace"
        xdt:Locator="XPath(/nlog:nlog/nlog:targets/nlog:target/nlog:connectionString)">
    ....put-connection-string-here....
  </nlog:connectionString>

</configuration>