3

<add name="ReleaseVersion" value="4"/>以下の app.configの value 属性を読み取ることができません。私は完全に途方に暮れています。XPath 値または Key 値が疑われます。

目標

  <Target Name="xxx"
          DependsOnTargets="CopyFilesToOutputDirectory" >

    <ItemGroup>
      <_DestinationAppConfigFile Include="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" />
    </ItemGroup>

    <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadAttribute"
                                       File="%(_DestinationAppConfigFile.FullPath)"
                                       XPath="/configuration/system.diagnostics/switches/add[@name='ReleaseVersion']/@value"
                                       Value="$(ReleaseVersion)" />

    <Error Condition = " '$(ReleaseVersion)'=='' "
           Text="Failed to read attribute." />

    <Message Text="ReleaseVersion: $(ReleaseVersion)"
             Importance="high" />

  </Target>

App.Config

  <?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <system.diagnostics>
      <switches>
        <!-- ReleaseVersion (Conditional release switch); 0- = PRODUCTION, 1 = MIRROR, 2 = EMERGENCYRELEASE, 3 = USERACCEPTANCETESTING, 4 = QA, 5 = DEVELOPMENT, 6 = DRN DEVELOPMENT -->
        <add name="ReleaseVersion" value="4"/>
        <!-- Stop (Stops execution to allow for Just-In-Time (JIT) debugging); 0 = CONTINUE EXECUTION, 1 = LAUNCH DEBUGGER -->
        <add name="Stop" value="0"/>
      </switches>
    </system.diagnostics>
  </configuration>

アップデート

http://msbuildextensionpack.codeplex.com/SourceControl/changeset/view/83099#1714660のコードを確認したところ、名前空間構文を使用して呼び出しがXmlFile.ReadAttribute行われました。それが問題かもしれません。SelectSingleNode

    private void ReadAttribute()
    {
        if (string.IsNullOrEmpty(this.XPath))
        {
            this.Log.LogError("XPath is Required");
            return;
        }

        this.LogTaskMessage(string.Format(CultureInfo.CurrentUICulture, "Read Attribute: {0}", this.XPath));
        XmlNode node = this.xmlFileDoc.SelectSingleNode(this.XPath, this.namespaceManager);
        if (node != null && node.NodeType == XmlNodeType.Attribute)
        {
            this.Value = node.Value;
        }
    }
4

1 に答える 1