转换非web配置文件替换元素
问题描述:
我有一个NLog.config,我必须指向不同的数据库进行生产。 我正在使用this 工具来转换它。 这是我的NLog.Config的一部分。转换非web配置文件替换元素
<?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>
我们需要改变整个元素,而不是属性。
答
与成功添加“n日志” 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>
还有另外一个目标“DebugLogs”像我这里exceptionlogs,我怎么更换第二个字符串? – SJMan
使用属性匹配指定目标:'XPath(/ nlog:nlog/nlog:targets/nlog:target [@ name ='ExceptionLog']/nlog:connectionString)',用'@ name = DebugLogs'添加另一个“替换” 。 – Gedrox