forked from Particular/NServiceBus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNuget.ps1
87 lines (70 loc) · 2.46 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
properties {
$ProductVersion = "4.0"
$PatchVersion = "0"
$BuildNumber = if($env:BUILD_NUMBER -ne $null) { $env:BUILD_NUMBER } else { "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 {
(dir -Path $nugetTempPath -Recurse -Filter '*.nuspec') | foreach {
Write-Host Creating NuGet spec file for $_.Name
[xml] $nuspec = Get-Content $_.FullName
$nugetVersion = $ProductVersion + "." + $PatchVersion
if($PreRelease -ne '') {
$nuspec.package.metadata.title += ' (' + $PreRelease + ')'
$nugetVersion = $ProductVersion + "." + $PatchVersion + "-" + $PreRelease + $BuildNumber
}
$nuspec.package.metadata.version = $nugetVersion
$nuspec | Select-Xml '//dependency[starts-with(@id, "NServiceBus")]' |% {
$_.Node.version = "[$nugetVersion]"
}
$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
}