forked from Particular/NServiceBus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNuget.ps1
105 lines (83 loc) · 3.05 KB
/
Nuget.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
properties {
$ProductVersion = "4.0"
$PatchVersion = "0"
$BuildNumber = "0"
$PreRelease = "alpha"
$NugetKey = ""
$UploadPackage = $false
}
$baseDir = Split-Path (Resolve-Path $MyInvocation.MyCommand.Path)
$toolsDir = "$baseDir\tools"
$nugetExec = "$toolsDir\NuGet\NuGet.exe"
$packageOutPutDir = "$baseDir\artifacts"
$nugetTempPath = "NugetTemp"
task default -depends Build
task Clean {
if ( -Not (Test-Path $packageOutPutDir))
{
New-Item $packageOutPutDir -ItemType Directory | Out-Null
} else {
Remove-Item ($packageOutPutDir + '\*.nupkg')
}
}
task Pack {
$v1Projects = @("NServiceBus.ActiveMQ.nuspec", "NServiceBus.RabbitMQ.nuspec", "NServiceBus.SqlServer.nuspec", "NServiceBus.Notifications.nuspec")
$nsbVersion = $ProductVersion + "." + $PatchVersion
if($PreRelease -ne '') {
$nsbVersion = "{0}.{1}-{2}{3}" -f $ProductVersion, $PatchVersion, $PreRelease, ($BuildNumber).PadLeft(4, '0')
}
(dir -Path $nugetTempPath -Recurse -Filter '*.nuspec') | foreach {
Write-Host Creating NuGet spec file for $_.Name
[xml] $nuspec = Get-Content $_.FullName
if([System.Array]::IndexOf($v1Projects, $_.Name) -eq -1){
$nugetVersion = $ProductVersion + "." + $PatchVersion
if($PreRelease -ne '') {
$nuspec.package.metadata.title += ' (' + $PreRelease + ')'
$nugetVersion = "{0}.{1}-{2}{3}" -f $ProductVersion, $PatchVersion, $PreRelease, ($BuildNumber).PadLeft(4, '0')
}
} else {
$nugetVersion = "1.0.0"
if($PreRelease -ne '') {
$nuspec.package.metadata.title += ' (' + $PreRelease + ')'
$nugetVersion = "1.0.0-{0}{1}" -f $PreRelease, ($BuildNumber).PadLeft(4, '0')
}
}
$nuspec.package.metadata.version = $nugetVersion
$nuspec | Select-Xml '//dependency[starts-with(@id, "NServiceBus")]' |% {
$_.Node.version = "[$nsbVersion]"
}
$nuspec | Select-Xml '//file[starts-with(@src, "\")]' |% {
$_.Node.src = $baseDir + $_.Node.src
}
if(Test-Path -Path ($_.DirectoryName + '\content')){
$fileElement = $nuspec.CreateElement('file')
$fileElement.SetAttribute('src', $_.DirectoryName + '\content\**')
$fileElement.SetAttribute('target', 'content')
$nuspec.package.files.AppendChild($fileElement) > $null
}
if(Test-Path -Path ($_.DirectoryName + '\tools')){
$fileElement = $nuspec.CreateElement('file')
$fileElement.SetAttribute('src', $_.DirectoryName + '\tools\**')
$fileElement.SetAttribute('target', 'tools')
$nuspec.package.files.AppendChild($fileElement) > $null
}
$nuspec.Save($_.FullName);
&$nugetExec pack $_.FullName -OutputDirectory $packageOutPutDir
}
}
task Push {
if(($UploadPackage) -and ($NugetKey -eq "")){
throw "Could not find the NuGet access key Package Cannot be uploaded without access key"
}
if($UploadPackage) {
(dir -Path $packageOutPutDir -Filter '*.nupkg') | foreach {
&$nugetExec push $_.FullName $NugetKey
}
}
}
task Init {
copy 'Nuget\' $nugetTempPath -Recurse -Force
}
task Build -depends Clean, Init, Pack, Push {
del $nugetTempPath -Recurse -Force -ErrorAction SilentlyContinue
}