[英]How can I read the value of an MSBuild PropertyGroup using PowerShell?
我有以下MSBuild( TestBuild.xml
)文件:
<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 }
我认为您需要执行MSBuild,运行自定义目标并捕获结果值。
将msbuild项目视为xml文件可能无法获得预期的结果。 考虑基于配置设置(调试与发布等)动态定义或有条件计算属性的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.