5

我正在尝试创建一个 web.config 转换文件,如果名称包含单词“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()or中的表达式Xpath()

您如何解决这个问题?

4

3 回答 3

4

I came up with the following solution:

<?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>

This will set all value attributes of <appSettings><add> elements that contain 'Config' in the key attribute to 'false'.

<add key="SomeOtherAppSettings"
     value="OriginalValue" />
<add key="An entry containing Config in the key attribute"
     value="false" />
于 2012-02-03T13:26:28.550 回答
1

此问题是Microsoft.Web.Publishing.Tasks.Dll随 Visual Studio 2010 安装的错误。

Microsoft 已更正 Visual Studio 2012 RTM 的问题(请参阅反馈)。

对于仍在使用 Visual Studio 2010 的用户,用更新的文件替换 inMicrosoft.Web.Publishing.Tasks.Dll将 解决问题并允许成功构建。$(MSBuildToolsPath)\MSBuild\Microsoft\VisualStudio\v10.0\Web$(MSBuildToolsPath)\MSBuild\Microsoft\VisualStudio\v11.0\Web

于 2013-08-26T20:57:36.827 回答
-1

这是 Visual Studio 2010 的一个错误。Microsoft 已在 Visual Studio 2012 中修复它

http://connect.microsoft.com/VisualStudio/feedback/details/618550/web-config-xpath-and-condition-locators-do-not-allow-commas-in-xpath-expression

于 2013-08-26T17:35:56.850 回答