-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathBuild.Pack.cs
134 lines (115 loc) · 5.63 KB
/
Build.Pack.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
130
131
132
133
using System;
using System.IO.Compression;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Build.Definition;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.MSBuild;
using Nuke.Common.Tools.NuGet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
using static Nuke.Common.Tools.NuGet.NuGetTasks;
using Project = Microsoft.Build.Evaluation.Project;
public partial class Build
{
// logic from 01_Build.bat
Target Pack => _ => _
.DependsOn(Compile)
.After(Test)
.OnlyWhenDynamic(() => IsRunningOnWindows)
.Executes(() =>
{
if (Configuration != Configuration.Release)
{
throw new InvalidOperationException("Cannot pack if compilation hasn't been done in Release mode, use --configuration Release");
}
var nugetVersion = VersionPrefix;
if (!string.IsNullOrWhiteSpace(VersionSuffix))
{
nugetVersion += "-" + VersionSuffix;
}
// it seems to cause some headache with publishing, so let's dotnet pack only files we know are suitable
var projects = SourceDirectory.GlobFiles("**/*.csproj")
.Where(x => !x.ToString().Contains("_build") &&
!x.ToString().Contains("NSwag.Console.csproj") && // legacy .net tool is not published as nuget package
!x.ToString().Contains("NSwagStudio") &&
!x.ToString().Contains("Test") &&
!x.ToString().Contains("Demo") &&
!x.ToString().Contains("Integration") &&
!x.ToString().Contains("x86") &&
!x.ToString().Contains("Launcher") &&
!x.ToString().Contains("Sample"))
.Select(x => Project.FromFile(x, new ProjectOptions()));
foreach (var project in projects)
{
DotNetPack(s => s
.SetProcessWorkingDirectory(SourceDirectory)
.SetProject(project.FullPath)
.SetAssemblyVersion(VersionPrefix)
.SetFileVersion(VersionPrefix)
.SetInformationalVersion(VersionPrefix)
.SetVersion(nugetVersion)
.SetConfiguration(Configuration)
.SetOutputDirectory(ArtifactsDirectory)
.SetDeterministic(IsServerBuild)
.SetContinuousIntegrationBuild(IsServerBuild)
);
}
Serilog.Log.Information("Build WiX installer");
(SourceDirectory / "NSwagStudio.Installer" / "bin").CreateOrCleanDirectory();
MSBuild(x => x
.SetTargetPath(GetProject("NSwagStudio.Installer"))
.SetTargets("Rebuild")
.SetAssemblyVersion(VersionPrefix)
.SetFileVersion(VersionPrefix)
.SetInformationalVersion(VersionPrefix)
.SetConfiguration(Configuration)
.SetMaxCpuCount(Environment.ProcessorCount)
.SetNodeReuse(IsLocalBuild)
.SetVerbosity(MSBuildVerbosity.Minimal)
.SetProperty("Deterministic", IsServerBuild)
.SetProperty("ContinuousIntegrationBuild", IsServerBuild)
);
// gather relevant artifacts
Serilog.Log.Information("Package nuspecs");
var apiDescriptionClientNuSpec = SourceDirectory / "NSwag.ApiDescription.Client" / "NSwag.ApiDescription.Client.nuspec";
var content = apiDescriptionClientNuSpec.ReadAllText();
content = content.Replace("<dependency id=\"NSwag.MSBuild\" version=\"1.0.0\" />", "<dependency id=\"NSwag.MSBuild\" version=\"" + nugetVersion + "\" />");
apiDescriptionClientNuSpec.WriteAllText(content);
var nuspecs = new[]
{
apiDescriptionClientNuSpec,
SourceDirectory / "NSwag.MSBuild" / "NSwag.MSBuild.nuspec",
SourceDirectory / "NSwagStudio.Chocolatey" / "NSwagStudio.nuspec"
};
foreach (var nuspec in nuspecs)
{
NuGetPack(x => x
.SetOutputDirectory(ArtifactsDirectory)
.SetConfiguration(Configuration)
.SetVersion(nugetVersion)
.SetTargetPath(nuspec)
);
}
var artifacts = Array.Empty<AbsolutePath>()
.Concat(RootDirectory.GlobFiles("**/Release/**/NSwag*.nupkg"))
.Concat(SourceDirectory.GlobFiles("**/Release/**/NSwagStudio.msi"));
foreach (var artifact in artifacts)
{
artifact.CopyToDirectory(ArtifactsDirectory);
}
// patch npm version
var npmPackagesFile = SourceDirectory / "NSwag.Npm" / "package.json";
content = npmPackagesFile.ReadAllText();
content = Regex.Replace(content, @"""version"": "".*""", @"""version"": """ + nugetVersion + @"""");
npmPackagesFile.WriteAllText(content);
// ZIP directories
ZipFile.CreateFromDirectory(NSwagNpmBinaries, ArtifactsDirectory / "NSwag.Npm.zip");
ZipFile.CreateFromDirectory(NSwagStudioBinaries, ArtifactsDirectory / "NSwag.zip");
// NSwagStudio.msi
(ArtifactsDirectory / "bin" / "NSwagStudio.Installer" / Configuration / "NSwagStudio.msi").CopyToDirectory(ArtifactsDirectory);
});
}