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?
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" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With