-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utilities.cs
129 lines (121 loc) · 5.4 KB
/
Utilities.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.IO;
using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.Core;
using Cake.Core.IO;
namespace Dnn.CakeUtils
{
public static class Utilities
{
public static void UpdateAssemblyInfo(this ICakeContext context, Solution sln, FilePath filePath)
{
var ai = new AssemblyInfo(filePath);
var project = filePath.FindProjectForPath(sln);
if (project != null)
{
ai.SetProperty("AssemblyVersion", project.version ?? sln.version);
ai.SetProperty("AssemblyFileVersion", project.version ?? sln.version);
if (project.owner == null)
{
ai.SetProperty("AssemblyTitle", sln.name);
ai.SetProperty("AssemblyDescription", sln.description);
ai.SetProperty("AssemblyCompany", sln.dnn.owner.organization);
ai.SetProperty("AssemblyCopyright", $"Copyright {System.DateTime.Now.Year} by {sln.dnn.owner.organization}");
}
ai.Write();
}
else
{
ai.SetProperty("AssemblyVersion", sln.version);
ai.SetProperty("AssemblyFileVersion", sln.version);
ai.SetProperty("AssemblyTitle", sln.name);
ai.SetProperty("AssemblyDescription", sln.description);
ai.SetProperty("AssemblyCompany", sln.dnn.owner.organization);
ai.SetProperty("AssemblyCopyright", $"Copyright {System.DateTime.Now.Year} by {sln.dnn.owner.organization}");
ai.Write();
}
}
public static void UpdateAssemblyInfoVersion(this ICakeContext context, Version version, string informationalVersion, FilePath filePath)
{
var ai = new AssemblyInfo(filePath);
ai.SetProperty("AssemblyVersion", version.ToString(3));
ai.SetProperty("AssemblyFileVersion", version.ToString(4));
if (!string.IsNullOrEmpty(informationalVersion))
{
ai.SetProperty("AssemblyInformationalVersion", informationalVersion);
}
ai.Write();
}
public static void UpdateCsProjFile(this ICakeContext context, Solution sln, FilePath filePath)
{
var projFile = new CsProjFile(filePath);
if (!projFile.IsNetCore)
{
return;
}
var project = filePath.FindProjectForPath(sln);
if (project != null)
{
projFile.SetProperty("AssemblyVersion", project.version ?? sln.version);
projFile.SetProperty("FileVersion", project.version ?? sln.version);
if (project.owner == null)
{
projFile.SetProperty("Product", sln.name);
projFile.SetProperty("Description", sln.description);
projFile.SetProperty("Company", sln.dnn.owner.organization);
projFile.SetProperty("Copyright", $"Copyright {System.DateTime.Now.Year} by {sln.dnn.owner.organization}");
}
projFile.Write();
}
else
{
projFile.SetProperty("AssemblyVersion", sln.version);
projFile.SetProperty("FileVersion", sln.version);
projFile.SetProperty("Product", sln.name);
projFile.SetProperty("Description", sln.description);
projFile.SetProperty("Company", sln.dnn.owner.organization);
projFile.SetProperty("Copyright", $"Copyright {System.DateTime.Now.Year} by {sln.dnn.owner.organization}");
projFile.Write();
}
}
public static string GetTextOrMdFile(this ICakeContext context, FilePath filePathWithExtension)
{
var filePath = filePathWithExtension.GetDirectory().CombineWithFilePath(filePathWithExtension.GetFilenameWithoutExtension());
context.Information("GetTextOrMdFile {0}", filePath);
if (File.Exists(filePath + ".md"))
{
context.Information("MD Found");
return context.ToHtml(filePath + ".md");
}
if (File.Exists(filePath + ".txt"))
{
context.Information("TXT Found");
return context.ReadFile(filePath + ".txt");
}
return "";
}
public static string ReadFile(this ICakeContext context, FilePath filePath)
{
return ReadFile(context.MakeAbsolute(filePath));
}
public static string ReadFile(FilePath filePath)
{
using (var sr = new System.IO.StreamReader(filePath.FullPath))
{
return sr.ReadToEnd();
}
}
public static void CreateResourcesFile(this ICakeContext context, DirectoryPath path, FilePath packagePath, FilePath packageName, string[] releaseFiles, string[] excludeFiles)
{
var files = context.GetFilesByPatterns(path, releaseFiles, excludeFiles);
if (files.Count > 0)
{
var resZip = context.ZipToBytes(path, files);
context.Information("Zipped resources file");
context.AddBinaryFileToZip(packagePath, resZip, packageName + ".zip", true);
}
context.Information("Added resources from " + path);
}
}
}