-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnuget.include.ps1
153 lines (120 loc) · 4.36 KB
/
nuget.include.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Based on :
# https://github.com/DefinitelyTyped/NugetAutomation/blob/master/CreatePackages.ps1
# https://github.com/peters/myget/blob/master/myget.include.ps1
. $rootFolder\tools.include.ps1
function Get-MostRecentNugetSpec {
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[string]$nugetPackageId
)
$feeedUrl= "http://packages.nuget.org/v1/FeedService.svc/Packages()?`$filter=Id%20eq%20'$nugetPackageId'&`$orderby=Version%20desc&`$top=1"
$webClient = new-object System.Net.WebClient
$feedResults = [xml]($webClient.DownloadString($feeedUrl))
return $feedResults.feed.entry
}
function Get-Last-NuGet-Version {
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[System.Xml.XmlElement] $spec
)
$v = $spec.properties.version."#text"
if(!$v) {
$v = $spec.properties.version
}
return [string]$v
}
function Get-Package-Id{
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[string]$rootFolder,
[parameter(Position = 1, Mandatory = $true, ValueFromPipeline = $true)]
[string]$project
)
$nuspecPath = [System.IO.Path]::Combine($rootFolder, $project) -ireplace ".(sln|csproj)$", ".nuspec"
[xml] $nuSpec = Get-Content -Path $nuspecPath
return $nuSpec.package.metadata.id;
}
function Update-Nuspec {
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[string]$rootFolder,
[parameter(Position = 1, Mandatory = $true, ValueFromPipeline = $true)]
[string]$project,
[parameter(Position = 1, Mandatory = $true, ValueFromPipeline = $true)]
$newPackagesVersions
)
$nuspecPath = [System.IO.Path]::Combine($rootFolder, $project) -ireplace ".(sln|csproj)$", ".nuspec"
[xml] $nuSpec = Get-Content $nuspecPath -Encoding utf8
$depedencies = $nuSpec.package.metadata.dependencies.group.dependency
if($depedencies.Count -gt 0)
{
$depedencies | ForEach-Object {
$depedency = $_
if($newPackagesVersions.ContainsKey($depedency.id))
{
$newVersion = $newPackagesVersions.Get_Item($depedency.id);
$depedency.version = $newVersion
}
}
$nuSpec.Save($nuspecPath)
}
}
function Build-Nupkg {
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[ValidatePattern(".(sln|csproj)$")]
[string]$project,
[parameter(Position = 1, Mandatory = $true, ValueFromPipeline = $true)]
[ValidatePattern("^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$")]
[string]$version,
[parameter(Position = 2, Mandatory = $true, ValueFromPipeline = $true)]
[string]$rootFolder,
[parameter(Position = 3, Mandatory = $true, ValueFromPipeline = $true)]
[string]$outputFolder,
[parameter(Position = 4, Mandatory = $true, ValueFromPipeline = $true)]
[string]$config
)
if(-not (Test-Path $project)) {
Die "Could not find project: $project"
}
$rootFolder = Normalize-Path $rootFolder
$nugetExe = NugetExe-Path
$buildFolder = Join-Path (Join-Path $rootFolder "bin") $config
$projectName = [System.IO.Path]::GetFileName($project) -ireplace ".(sln|csproj)$", ""
Write-Diagnostic "Nupkg: $projectName ($config)"
. $nugetExe pack $project -Build -OutputDirectory $outputFolder -NonInteractive `
-Version $version -Properties Configuration=$config
if($LASTEXITCODE -ne 0) {
Die "Build failed: $projectName" -exitCode $LASTEXITCODE
}
}
function Push-Nupkg {
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[string]$nupkg,
[parameter(Position = 1, Mandatory = $true, ValueFromPipeline = $true)]
[string]$nugetApiKey,
[parameter(Position = 2, Mandatory = $true, ValueFromPipeline = $true)]
[string]$source
)
$nugetExe = NugetExe-Path
. $nugetExe push $nupkg -ApiKey $nugetApiKey -Source $source -NonInteractive
}
function Packages-Clean {
param(
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[string]$rootFolder
)
Write-Diagnostic "Packages: Clean"
$binFolder = Join-Path $rootFolder "bin"
Get-ChildItem $binFolder |
Where-Object { $_.FullName -match ".nupkg$" } |
select -expand FullName |
sort Length -Descending |
ForEach-Object {
try{
Remove-Item $_ -Force -Recurse
}
catch{}
}
}