Search code examples
c#vcproj

Reading the .vcproj file with C#


We create the vcproj file with the makefileproj keyword so we can use our own build in VS. My question is, using C#, how do you read the "C++" from the following vcproj file:

<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
 ProjectType="Visual C++"
 Version="8.00"
 Name="TestCSProj"
 ProjectGUID="{840501C9-6AFE-8CD6-1146-84208624C0B0}"
 RootNamespace="TestCSProj"
 Keyword="MakeFileProj"
 >
 <Platforms>
  <Platform
   Name="x64"
  />
  <Platform
   Name="C++"     ===> I need to read "C++"
  />
 </Platforms>

I used XmlNode and got upto the second Platform:

String path = "C:\\blah\\TestCSProj\\TestCSProj\\TestCSProj.vcproj";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(fs);
XmlNodeList oldFiles = xmldoc.GetElementsByTagName("Platform");
XmlAttribute name = oldFiles[1].Attributes[0];
Console.WriteLine(name.Name);

This will print Name, but I need "C++". How do I read that?

Thank you very much in advance


Solution

  • Use name.Value.