forked from aloneguid/config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
118 lines (95 loc) · 2.7 KB
/
build.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
param(
[switch]
$Publish,
[string]
$NuGetApiKey
)
$gv = "3.2.0"
$vt = @{
"Config.Net.Integration.Storage.Net.csproj" = "1.0.0-alpha-1";
}
$VersionPrefix = "3"
$VersionSuffix = "2.0.0"
$Copyright = "Copyright (c) 2015-2017 by Ivan Gavryliuk"
$PackageIconUrl = "http://i.isolineltd.com/nuget/config.net.png"
$PackageProjectUrl = "https://github.com/aloneguid/config"
$RepositoryUrl = "https://github.com/aloneguid/config"
$Authors = "Ivan Gavryliuk (@aloneguid)"
$PackageLicenseUrl = "https://github.com/aloneguid/config/blob/master/LICENSE"
$RepositoryType = "GitHub"
$SlnPath = "src\Config.Net.sln"
function Set-VstsBuildNumber($BuildNumber)
{
Write-Verbose -Verbose "##vso[build.updatebuildnumber]$BuildNumber"
}
function Update-ProjectVersion($File)
{
$v = $vt.($File.Name)
if($v -eq $null) { $v = $gv }
$xml = [xml](Get-Content $File.FullName)
if($xml.Project.PropertyGroup.Count -eq $null)
{
$pg = $xml.Project.PropertyGroup
}
else
{
$pg = $xml.Project.PropertyGroup[0]
}
$parts = $v -split "\."
$bv = $parts[2]
if($bv.Contains("-")) { $bv = $bv.Substring(0, $bv.IndexOf("-"))}
$fv = "{0}.{1}.{2}.0" -f $parts[0], $parts[1], $bv
$av = "{0}.0.0.0" -f $parts[0]
$pv = $v
$pg.Version = $pv
$pg.FileVersion = $fv
$pg.AssemblyVersion = $av
Write-Host "$($File.Name) => fv: $fv, av: $av, pkg: $pv"
$pg.Copyright = $Copyright
$pg.PackageIconUrl = $PackageIconUrl
$pg.PackageProjectUrl = $PackageProjectUrl
$pg.RepositoryUrl = $RepositoryUrl
$pg.Authors = $Authors
$pg.PackageLicenseUrl = $PackageLicenseUrl
$pg.RepositoryType = $RepositoryType
$xml.Save($File.FullName)
}
function Exec($Command, [switch]$ContinueOnError)
{
Invoke-Expression $Command
if($LASTEXITCODE -ne 0)
{
Write-Error "command failed (error code: $LASTEXITCODE)"
if(-not $ContinueOnError.IsPresent)
{
exit 1
}
}
}
# General validation
if($Publish -and (-not $NuGetApiKey))
{
Write-Error "Please specify nuget key to publish"
exit 1
}
# Update versioning information
Get-ChildItem *.csproj -Recurse | Where-Object {-not($_.Name -like "*test*")} | % {
Update-ProjectVersion $_
}
Set-VstsBuildNumber $gv
# Restore packages
Exec "dotnet restore $SlnPath"
# Build solution
Get-ChildItem *.nupkg -Recurse | Remove-Item -ErrorAction Ignore
Exec "dotnet build $SlnPath -c release"
# publish the nugets
if($Publish.IsPresent)
{
Write-Host "publishing nugets..."
Get-ChildItem *.nupkg -Recurse | % {
$path = $_.FullName
Write-Host "publishing from $path"
Exec "nuget push $path -Source https://www.nuget.org/api/v2/package -ApiKey $NuGetApiKey" -ContinueOnError
}
}
Write-Host "build succeeded."