-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild-Package.ps1
101 lines (80 loc) · 2.26 KB
/
Build-Package.ps1
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
# Utilities
# Taken from psake https://github.com/psake/psake
<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
#>
function Exec
{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][scriptblock]$cmd,
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
$global:lastexitcode = 0
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}
function CleanContent([string]$path) {
if (Test-Path $path) {
$globPath = Join-Path $path *
Remove-Item -Force -Recurse $globPath
}
}
function CleanProject([string]$projectPath) {
@(
(Join-Path $projectPath bin\ ), `
(Join-Path $projectPath obj\ ), `
(Join-Path $projectPath publish\ ) `
) | ForEach-Object { CleanContent $_ }
}
function BuildVersioningOptions() {
$isContinuous = [bool]$env:APPVEYOR_BUILD_NUMBER
$isProduction = [bool]$env:APPVEYOR_REPO_TAG_NAME
$versioningOpt = if ($isContinuous) {
if ($isProduction) {
Write-Host "Continuous Delivery, Production package, keeping nuspec version."
@()
} else {
$suffix = "dev-$env:APPVEYOR_BUILD_NUMBER"
Write-Host "Continuous Delivery, Development package, version suffix: '$suffix'."
@( "-suffix", $suffix )
}
} else {
Write-Host "Local machine, keeping nuspec version."
@()
}
return $versioningOpt
}
###
# Clean
@(
"Content\CSharp.TestLibrary"
) | ForEach-Object { CleanProject $_ }
# Initialize
@(
"Content\CSharp.TestLibrary"
) | ForEach-Object { Exec { & dotnet restore $_ } }
# Build
@(
"Content\CSharp.TestLibrary"
) | ForEach-Object { Exec { & dotnet build -c Release $_ } }
# Test
@(
"Content\CSharp.TestLibrary"
) | ForEach-Object { Exec { & dotnet test -c Release $_ } }
# Package
$versioningOpt = BuildVersioningOptions
Exec {
& nuget pack DotNetNewNSpec.nuspec `
$versioningOpt `
-outputdirectory Content\CSharp.TestLibrary\publish\ `
-properties Configuration=Release
}