我正在尝试创建一个web。配置转换文件,如果名称中包含单词"config",则将appSettings值列表更改为"false"。
<add name="Config.Showlog" value ="true" />
转换文件有
<appSettings>
<add xdt:Transform="SetAttributes(value)"
value="false"
xdt:Locator="Condition(starts-with(@name,'Config')"/>
</appSettings>
Visual Studio 2010显示错误:
条件只需要1个参数
我还尝试了Xpath作为xdt:
定位器的属性,并得到了相同的错误。似乎问题来自VS 2010如何解析Condition()
或Xpath()
内的表达式。
如何解决这个问题?
我想出了以下解决方案:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add xdt:Transform="SetAttributes(value)"
value="false"
xdt:Locator="Condition(contains(@key, 'Config'))"/>
</appSettings>
</configuration>
这将把key
属性中包含'Config'的<appSettings><add>
元素的所有value
属性设置为'false'。
<add key="SomeOtherAppSettings"
value="OriginalValue" />
<add key="An entry containing Config in the key attribute"
value="false" />
此问题是Visual Studio 2010中安装的Microsoft.Web.Publishing.Tasks.Dll
中的一个错误。
微软已经更正了Visual Studio 2012 RTM的问题(见反馈)。
对于那些仍然在Visual Studio 2010上的人,用$(MSBuildToolsPath)MSBuildMicrosoftVisualStudiov11.0Web
中的更新文件替换$(MSBuildToolsPath)MSBuildMicrosoftVisualStudiov10.0Web
中的Microsoft.Web.Publishing.Tasks.Dll
将解决问题并允许成功构建。
这是Visual Studio 2010的一个bug。微软已经在Visual Studio 2012中修复了这个问题
http://connect.microsoft.com/VisualStudio/feedback/details/618550/web-config-xpath-and-condition-locators-do-not-allow-commas-in-xpath-expression