1

When parsing my *.csproj using Select-Xml, besides from the expected output i also get a concat of a parameter.

What is going on here?

$version = Select-Xml -Path $projectFilePath -XPath "/Project/PropertyGroup/Version"
Write-Host $version
Start-Sleep -Seconds 5
EXIT

this returns

1.0.1:D:\somepath\someproject.csproj

instead of

1.0.1

snippet of csproj

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netstandard1.3</TargetFramework>
    </PropertyGroup>
    <PropertyGroup>
        <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
        <AssemblyVersion>1.0.0.0</AssemblyVersion>
        <Version>1.0.1</Version>
    </PropertyGroup>
</Project>
Dbl
  • 5,634
  • 3
  • 41
  • 66

2 Answers2

3

Thanks for the snippet so now I could try myself.

This does work:

$version = Get-Content -Path $projectFilePath -Raw | Select-Xml -XPath "/Project/PropertyGroup/Version"
Write-Host $version
Theo
  • 57,719
  • 8
  • 24
  • 41
  • still a bit surprised why the original code results in that but ok... at least this works – Dbl Aug 27 '18 at 14:37
  • @Dbl Indeed. Seems like a bug to me. Also using `LiteralPath` appends the filename to the wanted result of the Xpath query.. – Theo Aug 27 '18 at 15:07
2

you could do this as well:

[xml]$x = get-content D:\somepath\someproject.csproj 
$x.project.propertygroup.version
Thom Schumacher
  • 1,469
  • 13
  • 24