This repository has been archived by the owner on Dec 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
default.ps1
100 lines (77 loc) · 3.5 KB
/
default.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
include .\extensions.ps1
properties {
# name of solution and nuspec.
$name = "Agdur"
$version = "1.0"
# files that should be part of the nuget.
$nuget_package_files = @( "$name.???" )
# shouldn't normally be any need change the variables below this comment.
$root = Resolve-Path .
$root_parent = Resolve-Path "$root\.."
# build
$build_path = "$root\build"
$build_binaries_path = "$build_path\binaries\"
$build_nuget_path = "$build_path\nuget"
# source
$source_path = "$root\src"
$solution_file = "$source_path\$name.sln"
# nuget
$nuspec = "$name.nuspec"
$nuspec_build_file = "$build_path\nuget\$nuspec"
$nuspec_file = "$root\$nuspec"
$nuget_apikey_path = "$root_parent\nuget.apikey"
$nuget_executable = "$source_path\.nuget\NuGet.exe"
$nuget_package = "$build_nuget_path\$name.$version.nupkg"
}
Framework "4.0"
task Default -depends build
task clean {
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue -LiteralPath $build_path
}
task build -depends clean {
# read metadata from nuspec and update AssemblyInfo.
$metadata = ([xml](Get-Content $nuspec_file)).package.metadata
# the AssemblyVersionAttribute is no fan of beta versions and will fail the build, thus
# we will be using the syntax major[.minor[.patch]].beta-version in AssemblyInfo.
$assembly_version = $version -replace '(\d+\\.)?(\d+\\.)?(\d+)-beta(\d+)', '$1$2$3.$4'
Generate-Assembly-Info `
-file "$source_path\AssemblyInfo.cs" `
-title $metadata.id + " $version" `
-description $metadata.description `
-product $metadata.id `
-version $assembly_version `
-copyright "Copyright (c) Mattias Rydengren 2013"
New-Item $build_binaries_path -ItemType Directory | Out-Null
exec { msbuild $solution_file /p:OutDir=$build_binaries_path /p:Configuration=Release /v:q }
}
task test -depends build {
$test_runner_executable = Resolve-Path "$root\packages\NUnit.Runners.*\tools\nunit-console-x86.exe"
$published_websites_path = "$build_binaries_path\_PublishedWebsites"
if (Test-Path $published_websites_path) {
# make sure tests find web project, if needed.
Move-Item $published_websites_path\$name.Web $build_binaries_path
Remove-Item $published_websites_path
}
Get-Item $build_binaries_path\*Tests*.dll |% {
exec { & $test_runner_executable $_ /noresult }
}
}
task nuget -depends build {
# copy files that should be part of the nuget.
New-Item $build_nuget_path\lib\net40 -ItemType Directory | Out-Null
$nuget_package_files |% { Copy-Item $build_binaries_path\$_ $build_nuget_path\lib\net40 }
# make a copy of the nuspec making temporary edits possible.
Copy-Item $nuspec_file $nuspec_build_file
# update version in the nuspec copy.
$content = [xml](Get-Content $nuspec_build_file)
$content.package.metadata.version = $version
$content.Save($nuspec_build_file)
exec { & $nuget_executable pack $nuspec_build_file -o $build_nuget_path }
}
task publish -depends test, nuget {
if ((Test-Path $nuget_apikey_path) -eq $false) {
return Write-Host "Missing NuGet API key: $nuget_apikey_path" -ForegroundColor Red
}
$apikey = Get-Content $nuget_apikey_path
exec { & $nuget_executable push $nuget_package $apikey }
}