Problem using xdt: locator by the condition "starts with" or "contains" in Web.config Conversion

I am trying to create a web.config conversion file that changes the list of appSettings to false if the name contains the word "Config".

<add name="Config.Showlog" value ="true" />

Conversion file has

<appSettings>
    <add xdt:Transform="SetAttributes(value)" 
         value="false" 
         xdt:Locator="Condition(starts-with(@name,'Config')"/>
</appSettings>

Visual Studio 2010 shows an error:

Condition Requires exactly 1 argument.

I also tried this with Xpath as an attribute for the locator xdt:and got the same error. The problem seems to be related to how VS 2010 parses the expression inside Condition()or Xpath().

How can you get around this problem?

+5
source share
3 answers

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>

value <appSettings><add>, "Config" key "false".

<add key="SomeOtherAppSettings"
     value="OriginalValue" />
<add key="An entry containing Config in the key attribute"
     value="false" />
+4

​​ Microsoft.Web.Publishing.Tasks.Dll, Visual Studio 2010.

Microsoft RTM Visual Studio 2012 (. ).

, Visual Studio 2010, Microsoft.Web.Publishing.Tasks.Dll $(MSBuildToolsPath)\MSBuild\Microsoft\VisualStudio\v10.0\Web $(MSBuildToolsPath)\MSBuild\Microsoft\VisualStudio\v11.0\Web .

+1

All Articles