Skip to content

Commit 9f2c129

Browse files
Tidy up build scripts
Do not edit the csproj outside CI. Use xplat path joining. Fix some casing. Make brace styles/spacing consistent. Add shebang for pwsh. Remove redundant variable.
1 parent c36712e commit 9f2c129

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

.config/dotnet-tools.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
]
1010
}
1111
}
12-
}
12+
}

build.bat

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ PUSHD %~dp0
33
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& './build.ps1'"
44

55
IF %errorlevel% neq 0 PAUSE
6-

build.cake

+39-31
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var configuration = Argument<string>("configuration", "Release");
99
// EXTERNAL NUGET TOOLS
1010
//////////////////////////////////////////////////////////////////////
1111

12-
#Tool "xunit.runner.console&version=2.4.1"
1312
#Tool "GitVersion.CommandLine&version=5.8.1"
13+
#Tool "xunit.runner.console&version=2.4.1"
1414

1515
//////////////////////////////////////////////////////////////////////
1616
// EXTERNAL NUGET LIBRARIES
@@ -32,15 +32,15 @@ var solutionPaths = solutions.Select(solution => solution.GetDirectory());
3232

3333
var srcDir = Directory("./src");
3434
var artifactsDir = Directory("./artifacts");
35-
var testResultsDir = artifactsDir + Directory("test-results");
35+
var testResultsDir = System.IO.Path.Combine(artifactsDir, Directory("test-results"));
3636

3737
// NuGet
38-
var nupkgDestDir = artifactsDir + Directory("nuget-package");
38+
var nupkgDestDir = System.IO.Path.Combine(artifactsDir, Directory("nuget-package"));
3939

40-
// Gitversion
40+
// GitVersion
4141
var gitVersionPath = ToolsExePath("GitVersion.exe");
42-
Dictionary<string, object> gitVersionOutput;
4342
var gitVersionConfigFilePath = "./GitVersionConfig.yaml";
43+
Dictionary<string, object> gitVersionOutput;
4444

4545
// Versioning
4646
string nugetVersion;
@@ -82,7 +82,8 @@ Teardown(_ =>
8282
Task("__Clean")
8383
.Does(() =>
8484
{
85-
DirectoryPath[] cleanDirectories = new DirectoryPath[] {
85+
DirectoryPath[] cleanDirectories = new DirectoryPath[]
86+
{
8687
testResultsDir,
8788
nupkgDestDir,
8889
artifactsDir
@@ -99,7 +100,7 @@ Task("__Clean")
99100
}
100101
});
101102

102-
Task("__RestoreNugetPackages")
103+
Task("__RestoreNuGetPackages")
103104
.Does(() =>
104105
{
105106
foreach(var solution in solutions)
@@ -115,7 +116,8 @@ Task("__UpdateAssemblyVersionInformation")
115116
var gitVersionSettings = new ProcessSettings()
116117
.SetRedirectStandardOutput(true);
117118

118-
try {
119+
try
120+
{
119121
IEnumerable<string> outputLines;
120122
StartProcess(gitVersionPath, gitVersionSettings, out outputLines);
121123

@@ -130,13 +132,13 @@ Task("__UpdateAssemblyVersionInformation")
130132
GitVersionConfigYaml deserialized = DeserializeYaml<GitVersionConfigYaml>(gitVersionYamlString.Replace("next-version", "NextVersion"));
131133
string gitVersionConfig = deserialized.NextVersion;
132134

133-
gitVersionOutput = new Dictionary<string, object>{
135+
gitVersionOutput = new Dictionary<string, object>
136+
{
134137
{ "NuGetVersion", gitVersionConfig + "-NotFromGitRepo" },
135138
{ "FullSemVer", gitVersionConfig },
136139
{ "AssemblySemVer", gitVersionConfig },
137140
{ "Major", gitVersionConfig.Split('.')[0] },
138141
};
139-
140142
}
141143

142144
Information("");
@@ -152,19 +154,21 @@ Task("__UpdateAssemblyVersionInformation")
152154

153155
Information("");
154156
Information("Mapping versioning information to:");
155-
Information("Appveyor build number -> {0}", appveyorBuildNumber);
156-
Information("Nuget package version -> {0}", nugetVersion);
157+
Information("AppVeyor build number -> {0}", appveyorBuildNumber);
158+
Information("NuGet package version -> {0}", nugetVersion);
157159
Information("AssemblyVersion -> {0}", assemblyVersion);
158160
Information("AssemblyFileVersion -> {0}", assemblySemver);
159161
Information("AssemblyInformationalVersion -> {0}", assemblySemver);
160162
});
161163

162164
Task("__UpdateDotNetStandardAssemblyVersionNumber")
165+
.WithCriteria(() => AppVeyor.IsRunningOnAppVeyor)
163166
.Does(() =>
164167
{
165168
Information("Updating Assembly Version Information");
166169

167-
var attributeToValueMap = new Dictionary<string, string>() {
170+
var attributeToValueMap = new Dictionary<string, string>()
171+
{
168172
{ "AssemblyVersion", assemblyVersion },
169173
{ "FileVersion", assemblySemver },
170174
{ "InformationalVersion", assemblySemver },
@@ -175,7 +179,8 @@ Task("__UpdateDotNetStandardAssemblyVersionNumber")
175179

176180
var csproj = File("./src/" + projectName + "/" + projectName + ".csproj");
177181

178-
foreach(var attributeMap in attributeToValueMap) {
182+
foreach(var attributeMap in attributeToValueMap)
183+
{
179184
var attribute = attributeMap.Key;
180185
var value = attributeMap.Value;
181186

@@ -185,7 +190,6 @@ Task("__UpdateDotNetStandardAssemblyVersionNumber")
185190
throw new Exception($"{attribute} version could not be updated in {csproj}.");
186191
}
187192
}
188-
189193
});
190194

191195
Task("__UpdateAppVeyorBuildNumber")
@@ -202,11 +206,12 @@ Task("__BuildSolutions")
202206
{
203207
Information("Building {0}", solution);
204208

205-
var dotNetCoreBuildSettings = new DotNetBuildSettings {
206-
Configuration = configuration,
207-
Verbosity = DotNetCoreVerbosity.Minimal,
208-
NoRestore = true,
209-
MSBuildSettings = new DotNetMSBuildSettings { TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error }
209+
var dotNetCoreBuildSettings = new DotNetBuildSettings
210+
{
211+
Configuration = configuration,
212+
Verbosity = DotNetCoreVerbosity.Minimal,
213+
NoRestore = true,
214+
MSBuildSettings = new DotNetMSBuildSettings { TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error },
210215
};
211216

212217
DotNetBuild(solution.ToString(), dotNetCoreBuildSettings);
@@ -216,28 +221,31 @@ Task("__BuildSolutions")
216221
Task("__RunTests")
217222
.Does(() =>
218223
{
219-
foreach(var specsProj in GetFiles("./src/**/*.Specs.csproj")) {
220-
DotNetTest(specsProj.FullPath, new DotNetTestSettings {
224+
foreach(var specsProj in GetFiles("./src/**/*.Specs.csproj"))
225+
{
226+
DotNetTest(specsProj.FullPath, new DotNetTestSettings
227+
{
221228
Configuration = configuration,
222-
NoBuild = true
229+
NoBuild = true,
223230
});
224231
}
225232
});
226233

227-
Task("__CreateSignedNugetPackage")
234+
Task("__CreateSignedNuGetPackage")
228235
.Does(() =>
229236
{
230237
var packageName = projectName;
231238

232239
Information("Building {0}.{1}.nupkg", packageName, nugetVersion);
233240

234-
var dotNetCorePackSettings = new DotNetPackSettings {
241+
var dotNetCorePackSettings = new DotNetPackSettings
242+
{
235243
Configuration = configuration,
236244
NoBuild = true,
237-
OutputDirectory = nupkgDestDir
245+
OutputDirectory = nupkgDestDir,
238246
};
239247

240-
DotNetPack($@"{srcDir}\{projectName}.sln", dotNetCorePackSettings);
248+
DotNetPack(System.IO.Path.Combine(srcDir, projectName + ".sln"), dotNetCorePackSettings);
241249
});
242250

243251
//////////////////////////////////////////////////////////////////////
@@ -246,13 +254,13 @@ Task("__CreateSignedNugetPackage")
246254

247255
Task("Build")
248256
.IsDependentOn("__Clean")
249-
.IsDependentOn("__RestoreNugetPackages")
257+
.IsDependentOn("__RestoreNuGetPackages")
250258
.IsDependentOn("__UpdateAssemblyVersionInformation")
251259
.IsDependentOn("__UpdateDotNetStandardAssemblyVersionNumber")
252260
.IsDependentOn("__UpdateAppVeyorBuildNumber")
253261
.IsDependentOn("__BuildSolutions")
254262
.IsDependentOn("__RunTests")
255-
.IsDependentOn("__CreateSignedNugetPackage");
263+
.IsDependentOn("__CreateSignedNuGetPackage");
256264

257265
///////////////////////////////////////////////////////////////////////////////
258266
// PRIMARY TARGETS
@@ -272,6 +280,6 @@ RunTarget(target);
272280
//////////////////////////////////////////////////////////////////////
273281

274282
string ToolsExePath(string exeFileName) {
275-
var exePath = System.IO.Directory.GetFiles(@"./tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault();
283+
var exePath = System.IO.Directory.GetFiles("./tools", exeFileName, SearchOption.AllDirectories).FirstOrDefault();
276284
return exePath;
277-
}
285+
}

build.ps1

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#! /usr/bin/env pwsh
12
<#
23
34
.SYNOPSIS
@@ -44,34 +45,33 @@ Param(
4445
Write-Host "Preparing to run build script..."
4546

4647
# Should we show verbose messages?
47-
if($Verbose.IsPresent)
48+
if ($Verbose.IsPresent)
4849
{
4950
$VerbosePreference = "continue"
5051
}
5152

5253
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
5354
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
54-
$CAKE_EXE = "dotnet dotnet-cake"
5555
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
5656
$DOTNET = "dotnet.exe"
5757

5858
# Should we use mono?
5959
$UseMono = "";
60-
if($Mono.IsPresent) {
60+
if ($Mono.IsPresent) {
6161
Write-Verbose -Message "Using the Mono based scripting engine."
6262
$UseMono = "-mono"
6363
}
6464

6565
# Should we use the new Roslyn?
6666
$UseExperimental = "";
67-
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
67+
if ($Experimental.IsPresent -and !($Mono.IsPresent)) {
6868
Write-Verbose -Message "Using experimental version of Roslyn."
6969
$UseExperimental = "-experimental"
7070
}
7171

7272
# Is this a dry run?
7373
$UseDryRun = "";
74-
if($WhatIf.IsPresent) {
74+
if ($WhatIf.IsPresent) {
7575
$UseDryRun = "-dryrun"
7676
}
7777

@@ -95,7 +95,7 @@ if (!(Test-Path $NUGET_EXE)) {
9595
$ENV:NUGET_EXE = $NUGET_EXE
9696

9797
# Restore tools from NuGet?
98-
if(-Not $SkipToolPackageRestore.IsPresent)
98+
if (-Not $SkipToolPackageRestore.IsPresent)
9999
{
100100
# Restore tools from NuGet.
101101
Push-Location
@@ -122,8 +122,7 @@ if(-Not $SkipToolPackageRestore.IsPresent)
122122
}
123123
}
124124

125-
126125
# Start Cake
127126
Write-Host "Running build script..."
128-
Invoke-Expression "$CAKE_EXE `"$Script`" --target=`"$Target`" --configuration=`"$Configuration`" --verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental"
129-
exit $LASTEXITCODE
127+
Invoke-Expression "dotnet dotnet-cake `"$Script`" --target=`"$Target`" --configuration=`"$Configuration`" --verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental"
128+
exit $LASTEXITCODE

0 commit comments

Comments
 (0)