gpt4 book ai didi

MSBuild.ExtensionPack.Xml.XmlFile TaskAction ="ReadAttribute"失败

转载 作者:行者123 更新时间:2023-12-02 16:48:39 28 4
gpt4 key购买 nike

我无法读取<add name="ReleaseVersion" value="4"/>的值属性在下面的 app.config 中。我完全不知所措。我怀疑 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>

应用程序配置

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

更新

我查看了 XmlFile.ReadAttribute 的代码在http://msbuildextensionpack.codeplex.com/SourceControl/changeset/view/83099#1714660它调用电话 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;
}
}

最佳答案

您的示例代码几乎是正确的;它只需要稍微改变一下 XmlFile 任务的用法。对 XmlFile ReadAttribute 的调用应将 Value 声明为任务的输出。为此,add the Output element to the task declaration ,将 TaskParameter 值设置为“Value”,并将 PropertyName 值设置为“ReleaseVersion”,类似于以下内容:

<MSBuild.ExtensionPack.Xml.XmlFile 
TaskAction="ReadAttribute"
File="[example-path-to-app-config]"
XPath="/configuration/system.diagnostics/switches/add[@name='ReleaseVersion']/@value">
<Output TaskParameter="Value" PropertyName="ReleaseVersion" />
<MSBuild.ExtensionPack.Xml.XmlFile>

进行更改后,假设您的 ToolsVersion 设置为 MSBuild 扩展包的特定实现所需的版本,则任务应该找到/读取属性值

关于MSBuild.ExtensionPack.Xml.XmlFile TaskAction ="ReadAttribute"失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15753628/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com