forked from aspnetboilerplate/aspnetboilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.cs
133 lines (120 loc) · 4.71 KB
/
Build.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.IO;
using System.Linq;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AppVeyor;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.Execution;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.MSBuild;
using Nuke.Common.Tools.NuGet;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
using static Nuke.Common.Tools.NuGet.NuGetTasks;
[CheckBuildProjectConfigurations]
[UnsetVisualStudioEnvironmentVariables]
[MSBuildVerbosityMapping]
[AzurePipelines(
AzurePipelinesImage.WindowsLatest,
InvokedTargets = new[] {nameof(Test)},
ExcludedTargets = new[] {nameof(Clean)},
NonEntryTargets = new[] {nameof(Restore), nameof(Compile)})]
[AppVeyor(
AppVeyorImage.VisualStudioLatest,
InvokedTargets = new[] {nameof(Test)},
AutoGenerate = false)]
class Build : NukeBuild
{
/// Support plugins are available for:
/// - JetBrains ReSharper https://nuke.build/resharper
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
public static int Main() => Execute<Build>(x => x.Compile);
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[CI] readonly AzurePipelines AzurePipelines;
[Solution] readonly Solution Solution;
Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
RootDirectory
.GlobDirectories(
"*/src/*/obj",
"*/src/*/bin",
"*/test/*/obj",
"*/test/*/bin")
.ForEach(DeleteDirectory);
});
Target Restore => _ => _
.Executes(() =>
{
NuGetRestore(_ => _
.SetTargetPath(Solution));
DotNetRestore(_ => _
.SetProjectFile(Solution));
});
Target Compile => _ => _
.DependsOn(Restore)
.Executes(() =>
{
MSBuild(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetProperty("SourceLinkCreate", true));
});
static AbsolutePath PackagesDirectory => RootDirectory / "output" / "packages";
Target Pack => _ => _
.DependsOn(Compile)
.Produces(PackagesDirectory / "*.nupkg")
.Executes(() =>
{
DotNetPack(_ => _
.SetConfiguration(Configuration)
.SetOutputDirectory(PackagesDirectory)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetProperty("SourceLinkCreate", true)
.CombineWith(
Solution.AllProjects.Where(x => x.SolutionFolder?.Name == "src"), (_, v) => _
.SetProject(v)));
});
[Partition(4)] readonly Partition TestPartition;
AbsolutePath TestResultDirectory => RootDirectory / "output" / "test-results";
Target Test => _ => _
.DependsOn(Compile)
.Partition(() => TestPartition)
.Executes(() =>
{
var allTestConfigurations =
from project in Solution.GetProjects("*Tests")
from targetFramework in project.GetTargetFrameworks()
select (project, targetFramework);
var relevantTestConfigurations = TestPartition.GetCurrent(allTestConfigurations);
try
{
DotNetTest(_ => _
.SetConfiguration(Configuration.Release)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetResultsDirectory(TestResultDirectory)
.CombineWith(relevantTestConfigurations, (_, v) => _
.SetProjectFile(v.project)
.SetFramework(v.targetFramework)
.SetLogger($"trx;LogFileName={v.project.Name}.trx")),
completeOnFailure: true);
}
finally
{
TestResultDirectory.GlobFiles("*.trx").ForEach(x =>
AzurePipelines?.PublishTestResults(
type: AzurePipelinesTestResultsType.VSTest,
title: $"{Path.GetFileNameWithoutExtension(x)} ({AzurePipelines.StageDisplayName})",
files: new string[] { x }));
}
});
}