- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法读取<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/
我无法读取的值属性在下面的 app.config 中。我完全不知所措。我怀疑 XPath 值或 Key 值。 目标 '$(OutDir)%(TargetPath)')" /
我试图通过对我的 msbuild 脚本中的文件执行正则表达式来替换 Visual Studio 安装项目中保存的 ProductName。要进行正则表达式替换,我正在尝试使用 msbuild exte
我有一个 MSBUILD 项目文件,我正在尝试 checkout 一些 xml 文件并更新版本元素,但似乎无法让它为我的生活工作。这似乎应该是一个简单的解决方案,但我无法让它工作。我有一个简单的 xm
我正在尝试安装 MS Build Extension Pack 以使用压缩任务。 我按照 the nuget web site 中的说明进行操作-- 即我在程序包管理器控制台中执行了 Install-
我是一名优秀的程序员,十分优秀!