Xpath not operator in Select-Xml via Powershell

1.2k Views Asked by At

I'm working with csproj files, and I'm trying to write a cmdlet that extracts all of the files referenced by a project file. This will include all of the Compile, EmbeddedResource, Resource, Content, and None elements (more importantly, their @Include values) but I specifically want to exclude the Reference elements as they refer to dlls, which aren't of concern to me.

I don't have a ton of experience, but I would think the xpath expression I would want would look something like this

$projectFile | Select-Xml -namespace @{msb="http://schemas.microsoft.com/developer/msbuild/2003"} -xpath "//msb:ItemGroup/*[not(self::node() = msb:Reference) and @Include]"

However, as soon as I try to introduce the self::node() my expression returns no nodes. I'm not 100% sure that self::node() is the right way to be doing this though. Any idea what I would change to make it return, conceptually, "all Include attribute values for nodes that are not Reference elements that are child elements of an ItemGroup element?"

1

There are 1 best solutions below

0
On BEST ANSWER

I think that you need:

//msb:ItemGroup/*[not(self::msb:Reference)]/@Include

Meaning: all the Include attributes of any child of msb:ItemGroup except for msb:Reference, in the whole document