Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Using xdt:locator by condition "starts-with" or "contains" in Web.config Transformation

I'm trying to create a web.config transform file that will change a list of appSettings value to "false" if the name contains the word "Config."

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

The transform 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 arguments.

I also tried that with Xpath as an attribute for xdt: locator and got the same error. It seems the problem comes from the how VS 2010 parses the expression inside Condition() or Xpath().

How can you work around this issue?

like image 728
Patt Avatar asked Oct 10 '22 06:10

Patt


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

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" />
like image 190
matthias.lukaszek Avatar answered Oct 15 '22 11:10

matthias.lukaszek


This issue is a bug in the Microsoft.Web.Publishing.Tasks.Dll installed with Visual Studio 2010.

Microsoft has corrected the issue with Visual Studio 2012 RTM (See feedback).

For those still on Visual Studio 2010, replacing Microsoft.Web.Publishing.Tasks.Dll in $(MSBuildToolsPath)\MSBuild\Microsoft\VisualStudio\v10.0\Web with updated file in $(MSBuildToolsPath)\MSBuild\Microsoft\VisualStudio\v11.0\Web will resolve issue and allow successful build.

like image 24
Nona Drake Avatar answered Oct 15 '22 10:10

Nona Drake