开发者

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

<appSetting开发者_开发知识库s>
    <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.


This is a bug with Visual Studio 2010. Microsoft has fixed it in Visual Studio 2012

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜