Skip to content

Commit 1eb45b6

Browse files
committed
Clean up build script
1 parent afc6ff0 commit 1eb45b6

2 files changed

Lines changed: 71 additions & 35 deletions

File tree

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/.vs/
2+
23
/build/bin/
3-
obj/
4+
/src/bin/
5+
46
/dist/
7+
58
/packages/
6-
/src/bin/
9+
/.dotnet/
710
/tools/
11+
12+
obj/

build/Tasks/Package.cs

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Engage.Dnn.SqlServerTypes.Build.Tasks
55
using Cake.Common.Build;
66
using Cake.Common.Diagnostics;
77
using Cake.Common.IO;
8+
using Cake.Common.IO.Paths;
89
using Cake.Common.Solution.Project.Properties;
910
using Cake.Common.Tools.MSBuild;
1011
using Cake.Common.Xml;
@@ -16,57 +17,87 @@ public sealed class Package : FrostingTask<Context>
1617
{
1718
public override void Run(Context context)
1819
{
20+
var version = ReadVersion(context);
21+
SetAssemblyInfoVersion(context, version);
22+
CleanAndBuild(context);
23+
1924
var dist = context.Directory("dist");
20-
var pkg = dist.Path.Combine("pkg");
21-
var pkgBin = pkg.Combine("bin");
22-
var packagesConfig = context.File("src/packages.config");
23-
var assemblyInfoPath = context.File("src/Properties/AssemblyInfo.cs");
25+
var (pkg, pkgBin) = CreateAndCleanDist(context, dist);
2426

25-
var version = context.XmlPeek(packagesConfig, "//package[@id=\"Microsoft.SqlServer.Types\"]/@version");
26-
context.Information($"Microsoft.SqlServer.Types NuGet package version {version}");
27+
var manifest = pkg.CombineWithFilePath("Engage.Dnn.SqlServerTypes.dnn");
28+
CopyPackageFiles(context, pkgBin, manifest);
29+
SetManifestVersions(context, manifest, version);
2730

28-
var assemblyInfo = context.ParseAssemblyInfo(assemblyInfoPath);
29-
context.CreateAssemblyInfo(assemblyInfoPath, new AssemblyInfoSettings
30-
{
31-
Version = version,
32-
FileVersion = version,
33-
InformationalVersion = version,
34-
Company = assemblyInfo.Company,
35-
Configuration = assemblyInfo.Configuration,
36-
CLSCompliant = assemblyInfo.ClsCompliant,
37-
Copyright = assemblyInfo.Copyright,
38-
Description = assemblyInfo.Description,
39-
Guid = string.IsNullOrWhiteSpace(assemblyInfo.Guid) ? null : assemblyInfo.Guid,
40-
Product = assemblyInfo.Product,
41-
Title = assemblyInfo.Title,
42-
Trademark = assemblyInfo.Trademark,
43-
ComVisible = assemblyInfo.ComVisible,
44-
InternalsVisibleTo = assemblyInfo.InternalsVisibleTo,
45-
});
31+
context.Zip(pkg, dist.Path.CombineWithFilePath($"Engage.Dnn.SqlServerTypes_{version}_Install.zip"));
4632

47-
var settings =
48-
new MSBuildSettings { Configuration = "Release", MaxCpuCount = 0, Verbosity = Verbosity.Minimal, }
49-
.WithRestore()
50-
.WithTarget("clean")
51-
.WithTarget("build");
52-
context.MSBuild("Engage.Dnn.SqlServerTypes.sln", settings);
33+
context.DeleteDirectory(pkg, new DeleteDirectorySettings { Force = true, Recursive = true, });
34+
}
5335

36+
private static (DirectoryPath pkg, DirectoryPath pkgBin) CreateAndCleanDist(Context context, ConvertableDirectoryPath dist)
37+
{
5438
context.CreateDirectory(dist);
5539
context.CleanDirectory(dist);
40+
var pkg = dist.Path.Combine("pkg");
41+
var pkgBin = pkg.Combine("bin");
5642
context.CreateDirectory(pkgBin);
5743

44+
return (pkg, pkgBin);
45+
}
46+
47+
private static string ReadVersion(Context context)
48+
{
49+
var packagesConfig = context.File("src/packages.config");
50+
var version = context.XmlPeek(packagesConfig, "//package[@id=\"Microsoft.SqlServer.Types\"]/@version");
51+
context.Information($"Microsoft.SqlServer.Types NuGet package version {version}");
52+
return version;
53+
}
54+
55+
private static void CopyPackageFiles(Context context, DirectoryPath pkgBin, FilePath manifest)
56+
{
5857
context.CopyFiles("src/bin/Release/**/*.dll", pkgBin, preserveFolderStructure: true);
59-
var manifest = pkg.CombineWithFilePath("Engage.Dnn.SqlServerTypes.dnn");
6058
context.CopyFile("src/bin/Release/Engage.Dnn.SqlServerTypes.dnn", manifest);
59+
}
6160

61+
private static void SetManifestVersions(Context context, FilePath manifest, string version)
62+
{
6263
context.XmlPoke(manifest, "//package/@version", version);
6364
context.XmlPoke(manifest, "//assembly[name/text()=\"Engage.Dnn.SqlServerTypes.dll\"]/version", version);
6465
context.XmlPoke(manifest, "//assembly[name/text()=\"Microsoft.SqlServer.Types.dll\"]/version", version);
6566
context.XmlPoke(manifest, "//assembly[name/text()=\"SqlServerSpatial140.dll\"]/version", version);
67+
}
6668

67-
context.Zip(pkg, dist.Path.CombineWithFilePath($"Engage.Dnn.SqlServerTypes_{version}_Install.zip"));
69+
private static void CleanAndBuild(Context context)
70+
{
71+
var settings = new MSBuildSettings { Configuration = "Release", MaxCpuCount = 0, Verbosity = Verbosity.Minimal, }
72+
.WithRestore()
73+
.WithTarget("clean")
74+
.WithTarget("build");
75+
context.MSBuild("Engage.Dnn.SqlServerTypes.sln", settings);
76+
}
6877

69-
context.DeleteDirectory(pkg, new DeleteDirectorySettings { Force = true, Recursive = true, });
78+
private static void SetAssemblyInfoVersion(Context context, string version)
79+
{
80+
var assemblyInfoPath = context.File("src/Properties/AssemblyInfo.cs");
81+
var assemblyInfo = context.ParseAssemblyInfo(assemblyInfoPath);
82+
context.CreateAssemblyInfo(
83+
assemblyInfoPath,
84+
new AssemblyInfoSettings
85+
{
86+
Version = version,
87+
FileVersion = version,
88+
InformationalVersion = version,
89+
Company = assemblyInfo.Company,
90+
Configuration = assemblyInfo.Configuration,
91+
CLSCompliant = assemblyInfo.ClsCompliant,
92+
Copyright = assemblyInfo.Copyright,
93+
Description = assemblyInfo.Description,
94+
Guid = string.IsNullOrWhiteSpace(assemblyInfo.Guid) ? null : assemblyInfo.Guid,
95+
Product = assemblyInfo.Product,
96+
Title = assemblyInfo.Title,
97+
Trademark = assemblyInfo.Trademark,
98+
ComVisible = assemblyInfo.ComVisible,
99+
InternalsVisibleTo = assemblyInfo.InternalsVisibleTo,
100+
});
70101
}
71102
}
72103
}

0 commit comments

Comments
 (0)