xml – 带有Powershell的.csproj文件中特定节点中的节点列表
发布时间:2020-12-15 23:56:31 所属栏目:百科 来源:网络整理
导读:我想请一些帮助,因为我完全迷失了. 我想检查.csproj文件的特定部分中的节点是否包含正确的数据.在下面的xml片段中,我想回到PropertyGroup下的“title”属于“Debug | x64”配置文件的值. csproj文件片段 ?xml version="1.0" encoding="utf-8"? Project Tools
我想请一些帮助,因为我完全迷失了.
我想检查.csproj文件的特定部分中的节点是否包含正确的数据.在下面的xml片段中,我想回到PropertyGroup下的“title”属于“Debug | x64”配置文件的值. csproj文件片段 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props')" /> <PropertyGroup> ... </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <DebugSymbols>true</DebugSymbols> <OutputPath>binx64Debug&;/OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <DebugType>full</DebugType> <PlatformTarget>x64</PlatformTarget> <ErrorReport>prompt</ErrorReport> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <!-- nuget stuff --> <title>Pet Project</title> </PropertyGroup> 这是我的powershell代码: function GetConfigPlatformNodeFromProjectFile($projectFile,$nodeIdentifier) { [xml] $pFile = Get-Content $projectFile $ns = New-Object System.Xml.XmlNamespaceManager -ArgumentList $pFile.NameTable $ns.AddNamespace("ns",$pFile.Project.GetAttribute("xmlns")) $nodes = $pFile.SelectNodes("//ns:Project/PropertyGroup[contains(@Condition,'Debug|x64')]",$ns) foreach($node in $nodes) { write-Host "node... " $node } } 问题是$节点将始终为0.根据这里的文章,它应该包含更多内容.路径还可以.我多次检查过. xmlns属性正确返回.我认为问题是xpath本身和命名空间,但是我通过其他XPath工具多次检查它. 我不知道在这种情况下我做错了什么. 提前感谢任何帮助! 安德拉什
你必须使用xpath吗?否则我会建议这样的事情:
$file = [xml](gc .test.csproj) $file.Project.PropertyGroup | ? Condition -Like '*Debug|x64*' | select Title (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |