I want to get a list of all project references in my csproj file using PowerShell. Currently I\'ve the following approach:
[xml]$csproj = Get-Content MyProject.c
The problem is the http://schemas.microsoft.com/developer/msbuild/2003
namespace. You need to take account of this namespace in your XPath expressions, as unprefixed element names in XPath refer to elements that are not in a namespace.
[xml]$csproj = Get-Content MyProject.csproj
$ns = new-object Xml.XmlNamespaceManager $csproj.NameTable
$ns.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003")
$refs = $csproj.SelectNodes("//msb:ProjectReference", $ns)
foreach($ref in $refs) {
# Later on output more useful information
Write-Host $ref.Name
}
(adapted from this answer)