我们使用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++“。我该怎么读呢?
非常感谢你提前
发布于 2010-06-06 02:51:33
使用name.Value。
发布于 2010-06-06 02:52:06
您可以使用Value属性访问该属性的值:
Console.WriteLine(name.Value);或者更好的是,通过名称来获取它,而不是索引,这样更短,更可靠:
Console.WriteLine(((XmlElement)oldFiles[1]).GetAttribute("Name"));GetAttribute方法直接以字符串的形式返回值。
https://stackoverflow.com/questions/2981598
复制相似问题