-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCsProjFile.cs
71 lines (64 loc) · 2.01 KB
/
CsProjFile.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
using System.Xml;
using Cake.Core.IO;
namespace Dnn.CakeUtils
{
public class CsProjFile : XmlDocument
{
private FilePath FilePath { get; set; }
public bool IsNetCore { get; set; } = false;
public CsProjFile(FilePath filePath)
{
FilePath = filePath;
base.Load(filePath.FullPath);
if (this.DocumentElement.HasAttribute("Sdk"))
{
IsNetCore = true;
}
}
public void SetProperty(string propName, string propValue)
{
var found = false;
foreach (XmlElement propGrp in DocumentElement.ChildNodes)
{
if (propGrp.Name == "PropertyGroup" && !propGrp.HasAttribute("Condition"))
{
foreach (XmlElement prop in propGrp.ChildNodes)
{
if (prop.Name == propName)
{
prop.InnerText = propValue;
found = true;
}
}
}
}
if (!found)
{
var newProp = CreateElement(propName);
newProp.InnerText = propValue;
foreach (XmlElement propGrp in DocumentElement.ChildNodes)
{
if (propGrp.Name == "PropertyGroup" && !propGrp.HasAttribute("Condition"))
{
propGrp.AppendChild(newProp);
found = true;
}
}
if (!found)
{
var newGrp = CreateElement("PropertyGroup");
newGrp.AppendChild(newProp);
DocumentElement.AppendChild(newGrp);
}
}
}
public void Write()
{
Write(FilePath);
}
public void Write(FilePath filePath)
{
Save(filePath.FullPath);
}
}
}