Parsing the XML in Powershell: Escaping various symbols in XPath


I need to parse the VS2022 .vbproj file to find the details of build configuration.
In powershell, I load the file and try to get to the necessary node. But I’m stuck with misleading PS error reporting and overwhelming amount of special symbols to escape…

I am looking for that line from .vbproj:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

here is my script:

$xml = [xml](Get-Content $xmlFile)

$propertyGroup = $xml.SelectSingleNode("//PropertyGroup[@Condition= ""''`$(Configuration)|`$(Platform)'' == ''Debug|AnyCPU''""]")
if ($propertyGroup) {
    Write-Host 'Element found.'
} else {
    Write-Host 'Element not found.'
}

Whatever I do, I either get either syntax errors, or “Element not found”… Please help!

Leave a Reply

Your email address will not be published. Required fields are marked *