Skip to content

Commit d260198

Browse files
author
Martijn van Put
committed
Update to dotnet tooling
1 parent 426b2ad commit d260198

File tree

5 files changed

+317
-57
lines changed

5 files changed

+317
-57
lines changed

.DS_Store

8 KB
Binary file not shown.

GitVersion.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mode: ContinuousDelivery
2+
next-version: 1.0.0
3+
branches: {}
4+
ignore:
5+
sha: []

build.cake

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// ADDINS/TOOLS
3+
///////////////////////////////////////////////////////////////////////////////
4+
#tool "nuget:?package=GitVersion.CommandLine"
5+
16
///////////////////////////////////////////////////////////////////////////////
27
// ARGUMENTS
38
///////////////////////////////////////////////////////////////////////////////
@@ -10,16 +15,33 @@ var configuration = Argument<string>("configuration", "Release");
1015
///////////////////////////////////////////////////////////////////////////////
1116

1217
var solutions = GetFiles("./**/*.sln");
13-
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
18+
var projects = GetFiles("./**/*.csproj").Select(x => x.GetDirectory());
19+
var myGetFeed = EnvironmentVariable("MYGET_SOURCE");
20+
var myGetApiKey = EnvironmentVariable("MYGET_API_KEY");
21+
var nuGetFeed = EnvironmentVariable("NUGET_SOURCE");
22+
var nuGetApiKey = EnvironmentVariable("NUGET_API_KEY");
23+
24+
GitVersion gitVersion;
1425

1526
///////////////////////////////////////////////////////////////////////////////
1627
// SETUP / TEARDOWN
1728
///////////////////////////////////////////////////////////////////////////////
1829

1930
Setup(context =>
2031
{
32+
gitVersion = GitVersion(new GitVersionSettings {
33+
UpdateAssemblyInfo = true
34+
});
35+
2136
// Executed BEFORE the first task.
22-
Information("Running tasks...");
37+
Information("Xer.Delegator");
38+
Information("Parameters");
39+
Information("///////////////////////////////////////////////////////////////////////////////");
40+
Information("Branch: {0}", gitVersion.BranchName);
41+
Information("Version semver: {0}", gitVersion.LegacySemVerPadded);
42+
Information("Version assembly: {0}", gitVersion.MajorMinorPatch);
43+
Information("Version informational: {0}", gitVersion.InformationalVersion);
44+
Information("///////////////////////////////////////////////////////////////////////////////");
2345
});
2446

2547
Teardown(context =>
@@ -37,23 +59,32 @@ Task("Clean")
3759
.Does(() =>
3860
{
3961
// Clean solution directories.
40-
foreach(var path in solutionPaths)
62+
foreach(var project in projects)
4163
{
42-
Information("Cleaning {0}", path);
43-
CleanDirectories(path + "/**/bin/" + configuration);
44-
CleanDirectories(path + "/**/obj/" + configuration);
64+
Information("Cleaning {0}", project);
65+
DotNetCoreClean(project.FullPath);
4566
}
4667
});
4768

4869
Task("Restore")
4970
.Description("Restores all the NuGet packages that are used by the specified solution.")
5071
.Does(() =>
5172
{
73+
var settings = new DotNetCoreRestoreSettings
74+
{
75+
ArgumentCustomization = args => args
76+
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
77+
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
78+
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
79+
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
80+
};
81+
5282
// Restore all NuGet packages.
5383
foreach(var solution in solutions)
5484
{
5585
Information("Restoring {0}...", solution);
56-
NuGetRestore(solution);
86+
87+
DotNetCoreRestore(solution.FullPath, settings);
5788
}
5889
});
5990

@@ -63,17 +94,22 @@ Task("Build")
6394
.IsDependentOn("Restore")
6495
.Does(() =>
6596
{
97+
var settings = new DotNetCoreBuildSettings
98+
{
99+
Configuration = configuration,
100+
ArgumentCustomization = args => args
101+
.Append("/p:Version={0}", gitVersion.LegacySemVerPadded)
102+
.Append("/p:AssemblyVersion={0}", gitVersion.MajorMinorPatch)
103+
.Append("/p:FileVersion={0}", gitVersion.MajorMinorPatch)
104+
.Append("/p:AssemblyInformationalVersion={0}", gitVersion.InformationalVersion)
105+
};
106+
66107
// Build all solutions.
67108
foreach(var solution in solutions)
68109
{
69110
Information("Building {0}", solution);
70111

71-
var settings = new DotNetCoreMSBuildSettings()
72-
.SetConfiguration(configuration)
73-
.SetMaxCpuCount(0) // Set this value to zero to use as many MSBuild processes as available CPUs.
74-
.TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error);
75-
76-
DotNetCoreMSBuild(solution.FullPath, settings);
112+
DotNetCoreBuild(solution.FullPath, settings);
77113
}
78114
});
79115

@@ -83,9 +119,15 @@ Task("Test")
83119
.Does(() =>
84120
{
85121
var projects = GetFiles("./Tests/**/*.Tests.csproj");
122+
var settings = new DotNetCoreTestSettings
123+
{
124+
Configuration = configuration,
125+
NoBuild = true,
126+
};
127+
86128
foreach(var project in projects)
87129
{
88-
DotNetCoreTest(project.FullPath);
130+
DotNetCoreTest(project.FullPath, settings);
89131
}
90132
});
91133

build.ps1

Lines changed: 139 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
##########################################################################
2+
# This is the Cake bootstrapper script for PowerShell.
3+
# This file was downloaded from https://github.com/cake-build/resources
4+
# Feel free to change this file to fit your needs.
5+
##########################################################################
6+
17
<#
28
39
.SYNOPSIS
@@ -15,13 +21,18 @@ The build script target to run.
1521
The build configuration to use.
1622
.PARAMETER Verbosity
1723
Specifies the amount of information to be displayed.
24+
.PARAMETER ShowDescription
25+
Shows description about tasks.
26+
.PARAMETER DryRun
27+
Performs a dry run.
1828
.PARAMETER Experimental
19-
Tells Cake to use the latest Roslyn release.
20-
.PARAMETER WhatIf
21-
Performs a dry run of the build script.
22-
No tasks will be executed.
29+
Uses the nightly builds of the Roslyn script engine.
2330
.PARAMETER Mono
24-
Tells Cake to use the Mono scripting engine.
31+
Uses the Mono Compiler rather than the Roslyn script engine.
32+
.PARAMETER SkipToolPackageRestore
33+
Skips restoring of packages.
34+
.PARAMETER ScriptArgs
35+
Remaining arguments are added here.
2536
2637
.LINK
2738
https://cakebuild.net
@@ -31,47 +42,71 @@ https://cakebuild.net
3142
[CmdletBinding()]
3243
Param(
3344
[string]$Script = "build.cake",
34-
[string]$Target = "Default",
35-
[string]$Configuration = "Release",
45+
[string]$Target,
46+
[string]$Configuration,
3647
[ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
37-
[string]$Verbosity = "Verbose",
48+
[string]$Verbosity,
49+
[switch]$ShowDescription,
50+
[Alias("WhatIf", "Noop")]
51+
[switch]$DryRun,
3852
[switch]$Experimental,
39-
[Alias("DryRun","Noop")]
40-
[switch]$WhatIf,
4153
[switch]$Mono,
4254
[switch]$SkipToolPackageRestore,
4355
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
4456
[string[]]$ScriptArgs
4557
)
4658

47-
Write-Host "Preparing to run build script..."
48-
49-
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
50-
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
51-
$NUGET_URL = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
52-
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
53-
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
59+
[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
60+
function MD5HashFile([string] $filePath)
61+
{
62+
if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
63+
{
64+
return $null
65+
}
5466

55-
# Should we use mono?
56-
$UseMono = "";
57-
if($Mono.IsPresent) {
58-
Write-Verbose -Message "Using the Mono based scripting engine."
59-
$UseMono = "-mono"
67+
[System.IO.Stream] $file = $null;
68+
[System.Security.Cryptography.MD5] $md5 = $null;
69+
try
70+
{
71+
$md5 = [System.Security.Cryptography.MD5]::Create()
72+
$file = [System.IO.File]::OpenRead($filePath)
73+
return [System.BitConverter]::ToString($md5.ComputeHash($file))
74+
}
75+
finally
76+
{
77+
if ($file -ne $null)
78+
{
79+
$file.Dispose()
80+
}
81+
}
6082
}
6183

62-
# Should we use the new Roslyn?
63-
$UseExperimental = "";
64-
if($Experimental.IsPresent -and !($Mono.IsPresent)) {
65-
Write-Verbose -Message "Using experimental version of Roslyn."
66-
$UseExperimental = "-experimental"
84+
function GetProxyEnabledWebClient
85+
{
86+
$wc = New-Object System.Net.WebClient
87+
$proxy = [System.Net.WebRequest]::GetSystemWebProxy()
88+
$proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
89+
$wc.Proxy = $proxy
90+
return $wc
6791
}
6892

69-
# Is this a dry run?
70-
$UseDryRun = "";
71-
if($WhatIf.IsPresent) {
72-
$UseDryRun = "-dryrun"
93+
Write-Host "Preparing to run build script..."
94+
95+
if(!$PSScriptRoot){
96+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
7397
}
7498

99+
$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
100+
$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
101+
$MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
102+
$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
103+
$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
104+
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
105+
$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
106+
$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
107+
$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
108+
$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
109+
75110
# Make sure tools folder exists
76111
if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
77112
Write-Verbose -Message "Creating tools directory..."
@@ -80,17 +115,19 @@ if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
80115

81116
# Make sure that packages.config exist.
82117
if (!(Test-Path $PACKAGES_CONFIG)) {
83-
Write-Verbose -Message "Downloading packages.config..."
84-
try { Invoke-WebRequest -Uri https://cakebuild.net/download/bootstrapper/packages -OutFile $PACKAGES_CONFIG } catch {
118+
Write-Verbose -Message "Downloading packages.config..."
119+
try {
120+
$wc = GetProxyEnabledWebClient
121+
$wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG) } catch {
85122
Throw "Could not download packages.config."
86123
}
87124
}
88125

89126
# Try find NuGet.exe in path if not exists
90127
if (!(Test-Path $NUGET_EXE)) {
91128
Write-Verbose -Message "Trying to find nuget.exe in PATH..."
92-
$existingPaths = $Env:Path -Split ';' | Where-Object { Test-Path $_ }
93-
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select-Object -First 1
129+
$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
130+
$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
94131
if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
95132
Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
96133
$NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
@@ -101,7 +138,8 @@ if (!(Test-Path $NUGET_EXE)) {
101138
if (!(Test-Path $NUGET_EXE)) {
102139
Write-Verbose -Message "Downloading NuGet.exe..."
103140
try {
104-
(New-Object System.Net.WebClient).DownloadFile($NUGET_URL, $NUGET_EXE)
141+
$wc = GetProxyEnabledWebClient
142+
$wc.DownloadFile($NUGET_URL, $NUGET_EXE)
105143
} catch {
106144
Throw "Could not download NuGet.exe."
107145
}
@@ -111,29 +149,87 @@ if (!(Test-Path $NUGET_EXE)) {
111149
$ENV:NUGET_EXE = $NUGET_EXE
112150

113151
# Restore tools from NuGet?
114-
if(-Not $SkipToolPackageRestore.IsPresent)
115-
{
116-
# Restore packages from NuGet.
152+
if(-Not $SkipToolPackageRestore.IsPresent) {
117153
Push-Location
118154
Set-Location $TOOLS_DIR
119155

156+
# Check for changes in packages.config and remove installed tools if true.
157+
[string] $md5Hash = MD5HashFile($PACKAGES_CONFIG)
158+
if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
159+
($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
160+
Write-Verbose -Message "Missing or changed package.config hash..."
161+
Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery |
162+
Remove-Item -Recurse
163+
}
164+
120165
Write-Verbose -Message "Restoring tools from NuGet..."
121166
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
167+
168+
if ($LASTEXITCODE -ne 0) {
169+
Throw "An error occurred while restoring NuGet tools."
170+
}
171+
else
172+
{
173+
$md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
174+
}
122175
Write-Verbose -Message ($NuGetOutput | out-string)
123176

124177
Pop-Location
125-
if ($LASTEXITCODE -ne 0)
126-
{
127-
exit $LASTEXITCODE
178+
}
179+
180+
# Restore addins from NuGet
181+
if (Test-Path $ADDINS_PACKAGES_CONFIG) {
182+
Push-Location
183+
Set-Location $ADDINS_DIR
184+
185+
Write-Verbose -Message "Restoring addins from NuGet..."
186+
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
187+
188+
if ($LASTEXITCODE -ne 0) {
189+
Throw "An error occurred while restoring NuGet addins."
190+
}
191+
192+
Write-Verbose -Message ($NuGetOutput | out-string)
193+
194+
Pop-Location
195+
}
196+
197+
# Restore modules from NuGet
198+
if (Test-Path $MODULES_PACKAGES_CONFIG) {
199+
Push-Location
200+
Set-Location $MODULES_DIR
201+
202+
Write-Verbose -Message "Restoring modules from NuGet..."
203+
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
204+
205+
if ($LASTEXITCODE -ne 0) {
206+
Throw "An error occurred while restoring NuGet modules."
128207
}
208+
209+
Write-Verbose -Message ($NuGetOutput | out-string)
210+
211+
Pop-Location
129212
}
130213

131214
# Make sure that Cake has been installed.
132215
if (!(Test-Path $CAKE_EXE)) {
133216
Throw "Could not find Cake.exe at $CAKE_EXE"
134217
}
135218

219+
220+
221+
# Build Cake arguments
222+
$cakeArguments = @("$Script");
223+
if ($Target) { $cakeArguments += "-target=$Target" }
224+
if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
225+
if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
226+
if ($ShowDescription) { $cakeArguments += "-showdescription" }
227+
if ($DryRun) { $cakeArguments += "-dryrun" }
228+
if ($Experimental) { $cakeArguments += "-experimental" }
229+
if ($Mono) { $cakeArguments += "-mono" }
230+
$cakeArguments += $ScriptArgs
231+
136232
# Start Cake
137233
Write-Host "Running build script..."
138-
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -target=`"$Target`" -configuration=`"$Configuration`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $UseExperimental $ScriptArgs"
234+
&$CAKE_EXE $cakeArguments
139235
exit $LASTEXITCODE

0 commit comments

Comments
 (0)