I need to get a list of files from a VS project file. csproj file is XML file, so I use linq to xml to parse it. The problem is in default namespace of csproj file, it is declared like:
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
Here is the code I use to find "Compile" elements in a csproj file:
XmlReader reader = XmlReader.Create(projectFilePath);
XDocument doc = XDocument.Load(reader);
XmlNameTable nameTable = reader.NameTable;
XmlNamespaceManager nsManager = new XmlNamespaceManager(nameTable);
XNamespace nms = doc.Root.GetDefaultNamespace();
nsManager.AddNamespace("", nms.NamespaceName);
List<XElement> csFiles = new List<XElement>(doc.Root.XPathSelectElements("//Compile", nsManager));
doc.Root.XPathSelectElements returns an empty list.
nsManager.DefaultNamespace has value "http://schemas.microsoft.com/developer/msbuild/2003".
But nsManager.LookupNamespace("xmlns") returns default XML namespace: "http://www.w3.org/2000/xmlns/".
How to change the xmlns namespace value?