Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath not operator in Select-Xml via Powershell

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?"

like image 307
bwerks Avatar asked Jul 17 '26 14:07

bwerks


1 Answers

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


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!