forked from NuGet/Home
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-nuget.ps1
219 lines (179 loc) · 5.57 KB
/
build-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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
param (
[ValidateSet("debug", "release")][string]$Configuration="debug",
[switch]$SkipTests,
[switch]$Fast,
[switch]$CleanCache,
[switch]$PublicRelease,
# The first repo to build. Default is NuGet3. This allows to us to do pseudo incremental
# build.
# E.g. if there are changes in NuGet.PackageManagement, then the repos we need to build
# are NuGet.PackageManagement and NuGet.VisualStudioExtension. We don't need to build NuGet3.
# So we can run the command as
# build-nuget -FirstRepo NuGet.PackageManagement
# or
# build-nuget -FirstRepo pm
#
[ValidateSet("NuGet3", "NuGet.PackageManagement", "NuGet.VisualStudioExtension",
"pm", "vsix")][string]$FirstRepo = "NuGet3"
)
# Build a project k project.
# - projectDirectory is the root directory of the project
# - outputDirectory is the directory where the generated nupkg files are copied to
function ProjectKBuild([string]$projectDirectory, [string]$outputDirectory)
{
Write-Host "======== Building in $ProjectDirectory ======"
# build the project
pushd $projectDirectory
if ($Fast)
{
# build with DNX in parallel, do not use this if there are build errors
.\build.cmd --parallel verify
}
else
{
.\build.cmd
}
$result = $lastexitcode
popd
Write-Output "last exit code $result"
if ($result -ne 0)
{
$errorMessage = "Build failed. Project directory is $projectDirectory"
throw $errorMessage
}
# copy the generated nupkgs
$artifactDirectory = Join-Path $projectDirectory "artifacts\build"
Copy-Item (Join-Path $artifactDirectory "*.nupkg") $outputDirectory -Verbose:$true
ls $outputDirectory NuGet.CommandLine*.nupkg | rm
}
function BuildNuGetPackageManagement()
{
pushd "$GitRoot\NuGet.PackageManagement"
$env:NUGET_PUSH_TARGET = $packagesDirectory
if ($PublicRelease)
{
$args = @{ Configuration = $Configuration; PushTarget = $packagesDirectory; PublicRelease="true"; }
}
else
{
$args = @{ Configuration = $Configuration; PushTarget = $packagesDirectory; }
}
if ($SkipTests -or $Fast)
{
$args.Add("SkipTests", $true)
}
& "$GitRoot\NuGet.PackageManagement\pack.ps1" @args
$result = $lastexitcode
# ILMerge nuget.exe
cd "$GitRoot\NuGet.PackageManagement\src\NuGet.CommandLine\bin\$Configuration"
if (Test-Path Merged)
{
rmdir Merged\nuget.exe
}
else
{
mkdir Merged
}
if ($result -eq 0)
{
Write-Output "Creating the ilmerged nuget.exe"
& $ILMerge NuGet.exe NuGet.Client.dll NuGet.Commands.dll NuGet.Configuration.dll NuGet.ContentModel.dll NuGet.Core.dll NuGet.DependencyResolver.Core.dll NuGet.DependencyResolver.dll NuGet.Frameworks.dll NuGet.LibraryModel.dll NuGet.Logging.dll NuGet.PackageManagement.dll NuGet.Packaging.Core.dll NuGet.Packaging.Core.Types.dll NuGet.Packaging.dll NuGet.ProjectManagement.dll NuGet.ProjectModel.dll NuGet.Protocol.Core.Types.dll NuGet.Protocol.Core.v2.dll NuGet.Protocol.Core.v3.dll NuGet.Repositories.dll NuGet.Resolver.dll NuGet.RuntimeModel.dll NuGet.Versioning.dll Microsoft.Web.XmlTransform.dll Newtonsoft.Json.dll /log:mergelog.txt /out:Merged\nuget.exe
}
popd
if ($result -ne 0)
{
throw "Build failed"
}
}
function BuildVSExtension()
{
pushd "$GitRoot\NuGet.VisualStudioExtension"
$env:VisualStudioVersion="14.0"
& msbuild build\build.proj /t:Clean /m
& msbuild build\build.proj /t:RestorePackages /p:NUGET_BUILD_FEEDS=$packagesDirectory
if ($LASTEXITCODE -ne 0)
{
popd
throw "Build failed"
}
if($PublicRelease)
{
$Release = 'true'
}
else
{
$Release = 'false'
}
& msbuild NuGet.VisualStudioExtension.sln /p:Configuration=$Configuration /p:VisualStudioVersion="14.0" /p:DeployExtension=false /p:PublicRelease=$Release
if ($LASTEXITCODE -ne 0)
{
popd
throw "Build failed"
}
popd
}
# Clean the machine level cache from all package
function CleanCache()
{
Write-Host Removing MEF cache
if (Test-Path $env:localappdata\Microsoft\VisualStudio\14.0Exp)
{
rm -r $env:localappdata\Microsoft\VisualStudio\14.0Exp -Force
}
Write-Host Removing DNX packages
if (Test-Path $env:userprofile\.dnx\packages)
{
rm -r $env:userprofile\.dnx\packages -Force
}
Write-Host Removing .NUGET packages
if (Test-Path $env:userprofile\.nuget\packages)
{
rm -r $env:userprofile\.nuget\packages -Force
}
Write-Host Removing DNU cache
if (Test-Path $env:localappdata\dnu\cache)
{
rm -r $env:localappdata\dnu\cache -Force
}
Write-Host Removing NuGet web cache
if (Test-Path $env:localappdata\NuGet\v3-cache)
{
rm -r $env:localappdata\NuGet\v3-cache -Force
}
Write-Host Removing NuGet machine cache
if (Test-Path $env:localappdata\NuGet\Cache)
{
rm -r $env:localappdata\NuGet\Cache -Force
}
}
$ilmerge = Join-Path $PSScriptRoot "ilmerge.exe"
# set environment used by k
$env:Configuration=$Configuration
$timestamp = [DateTime]::UtcNow.ToString("yyMMddHHmmss");
$env:DNX_BUILD_VERSION="local-$timestamp"
# Create the packages directory
$GitRoot = Get-Location
$packagesDirectory = "$GitRoot\nupkgs"
if (!(Test-Path $packagesDirectory))
{
mkdir $packagesDirectory
}
if($CleanCache)
{
CleanCache
}
if ($FirstRepo -eq "NuGet3")
{
# build NuGet3
rm "$packagesDirectory\*.nupkg"
ProjectKBuild "$GitRoot\NuGet3" "$GitRoot\nupkgs"
}
if (($FirstRepo -eq "NuGet3") -or
($FirstRepo -eq "NuGet.PackageManagement") -or
($FirstRepo -eq "pm"))
{
# build NuGet.PackageManagement
BuildNuGetPackageManagement
}
# build NuGet.VisualStudioExtension
BuildVSExtension