[英]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.