forked from ssvaidya/VSProjectConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVSProjectInfo.cs
99 lines (85 loc) · 3.11 KB
/
VSProjectInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace ProjectConverter
{
public class VSProjectInfo: IVSIinfo
{
public const string VSProjNamespace = "http://schemas.microsoft.com/developer/msbuild/2003";
public VSProjectInfo(string strProjectFilePath)
{
ReadProjectFile(strProjectFilePath);
}
public string OldToolsVersion
{
get;
set;
}
public string ProductVersion
{
get;
set;
}
public string ProjectVersion
{
get;
set;
}
public string TargetFrameworkVersion
{
get;
set;
}
public string ToolsVersion
{
get;
set;
}
/// <summary>
/// Reads an existing Visual Studio project file
/// </summary>
/// <param name="strProjectFilePath">string path to a Visual Studio project file</param>
public void ReadProjectFile(string strProjectFilePath)
{
string strTargetFramework = string.Empty, strOldToolsVersion = string.Empty;
const string TargetFrameworkNode = "TargetFrameworkVersion";
const string OldToolsVersionNode = "OldToolsVersion";
const string ProductVersionNode = "ProductVersion";
XNamespace xProjNS = VSProjNamespace;
//Load the project file into memory
XElement xProjElement = XElement.Load(strProjectFilePath);
//TODO: Determine if there is a better method to LINQ to XML to avoid iterating over entire Xml hierarchy
foreach (var item in xProjElement.Elements(xProjNS + "PropertyGroup").Descendants())
{
//Get the TargetFrameworkVersion Xml Node
if (item.Name.LocalName.Equals(TargetFrameworkNode))
{
//Get the text contents of the target framework node
var xTargetFramework = item;
this.TargetFrameworkVersion = item.Value;
System.Diagnostics.Debug.WriteLine(item.Value);
}//if
//Get the OldToolsVersion Xml Node
if (item.Name.LocalName.Equals(OldToolsVersionNode))
{
//Get the text contents of the target framework node
var xOldToolsVersion = item;
this.OldToolsVersion = item.Value;
System.Diagnostics.Debug.WriteLine(item.Value);
}//if
//Get the ProductVersion Xml Node
if (item.Name.LocalName.Equals(ProductVersionNode))
{
//Get the text contents of the target framework node
var xProductVersionNode = item;
this.ProductVersion = item.Value;
System.Diagnostics.Debug.WriteLine(item.Value);
}//if
}//foreach
}//method: ReadProjectFile
}
}