使用PowerShell Core 7.4.6。
给定文件
/path/to/file.csproj
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="Path\To\Something.csproj" />
</ItemGroup>
</Project>
我希望以下代码段将选择
ProjectReference
使用内置XPath从该文件中提取节点
ends-with
功能
select-xml -path "/path/to/file.csproj" `
-xpath "/Project/ItemGroup/ProjectReference[ends-with(@Include, 'Something.csproj')]"
但相反,它会产生错误
Select-Xml: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.
如果我尝试使用XPath函数名称空间显式地限定其范围
select-xml -path "/path/to/file.csproj" `
-xpath "/Project/ItemGroup/ProjectReference[fn:ends-with(@Include, 'Something.csproj')]" `
-namespace @{ "fn" = "http://www.w3.org/2005/xpath-functions" }
我得到了一个不同的错误
Select-Xml: XsltContext is needed for this query because of an unknown function.
我错过了什么?
The documentation for
Select-Xml
没有提到对调用XPath函数的限制,因此我假设它们是本机支持的。