我有以下 MSBuild (TestBuild.xml
) file:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<Import Project="folderA\A.targets"/>
<!-- bunch of stuff -->
<PropertyGroup>
<ApplicationName>MyApp</ApplicationName>
<SolutionName>MySolution</SolutionName>
<VersionFile>Version.cs</VersionFile>
<TargetPackageVersion>$(RELEASE_VERSION)</TargetPackageVersion>
<BuildPlatform Condition=" '$(BuildPlatform)' == '' ">x86</BuildPlatform>
<TestAssembliesPattern>*Tests*.dll</TestAssembliesPattern>
...
</PropertyGroup>
<!-- bunch of more stuff -->
<PropertyGroup>
<ConfigurationContentFolder>$(MSBuildProjectDirectory)\Configuration</ConfigurationContentFolder>
<PluginName>ABC</PluginName>
</PropertyGroup>
...
</Project>
我希望能够获得的值VersionFile
在这种情况下的节点Version.cs
我一直在使用 XPath,希望以下内容能够工作:
$xdoc = [xml] $xdoc = get-content ".\TestBuild.xml"
$xdoc.SelectSingleNode("//VersionFile") | select { $_.InnerText }
$xdoc.SelectSingleNode("VersionFile") | select { $_.InnerText }
但到目前为止我还没有任何运气。任何帮助深表感谢。
Xml 有一个命名空间,因此您必须限定元素名称。使用Select-Xml
使用命名空间评估 XPath:
$xml = [xml](get-content ".\TestBuild.xml")
$ns = @{ msb = "http://schemas.microsoft.com/developer/msbuild/2003" }
Select-Xml $xml -Namespace $ns -XPath "//msb:VersionFile" | foreach { $_.Node.InnerText }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)