5

名前に「Config」という単語が含まれている場合、appSettings値のリストを「false」に変更するweb.config変換ファイルを作成しようとしています。

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

変換ファイルには

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

VisualStudio2010にエラーが表示されます。

条件正確に1つの引数が必要です。

また、ロケーターの属性としてXpathを使用してそれを試しましたxdt:が、同じエラーが発生しました。問題は、VS2010がCondition()or内の式を解析する方法に起因しているようXpath()です。

この問題をどのように回避できますか?

4

3 に答える 3

4

私は次の解決策を思いつきました:

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

これにより、属性に「Config」を含む要素のすべてのvalue属性が「false」に設定されます。<appSettings><add>key

<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.DllVisual Studio 2010 と共にインストールされた のバグです。

Microsoft は、Visual Studio 2012 RTM の問題を修正しました (フィードバックを参照してください)。

まだ Visual Studio 2010 を使用している場合は、 を更新されたファイルに置き換えるMicrosoft.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 に答える