1

我们使用 makefileproj 关键字创建 vcproj 文件,以便我们可以在 VS 中使用我们自己的构建。我的问题是,使用 C#,如何从以下 vcproj 文件中读取“C++”:

<?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>

我使用了 XmlNode 并进入了第二个平台:

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);

这将打印名称,但我需要“C++”。我怎么读?

非常感谢您提前

4

2 回答 2

1

您可以使用属性访问属性的值Value

Console.WriteLine(name.Value);

或者更好的是,通过名称而不是索引来获取它,这样更短更可靠:

Console.WriteLine(((XmlElement)oldFiles[1]).GetAttribute("Name"));

GetAttribute方法直接将值作为字符串返回。

于 2010-06-05T18:52:06.290 回答
0

使用name.Value.

于 2010-06-05T18:51:32.580 回答