forked from NuGet/NuGet.Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
337 lines (273 loc) · 9.46 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
param (
[ValidateSet("debug", "release")][string]$Configuration="debug",
[ValidateSet("Release","rtm", "rc", "beta", "local")][string]$ReleaseLabel="local",
[string]$BuildNumber,
[switch]$SkipTests,
[switch]$SkipRestore,
[switch]$CleanCache,
[switch]$SkipILMerge,
[switch]$DelaySign,
[string]$MSPFXPath,
[string]$NuGetPFXPath,
[switch]$SkipXProj,
[switch]$SkipSubModules
)
###Functions###
function RestoreXProj($file)
{
$ext = [System.IO.Path]::GetExtension($file.FullName)
if ($ext -eq ".xproj")
{
$xprojDir = [System.IO.Path]::GetDirectoryName($file.FullName)
$projectJsonFile = [System.IO.Path]::Combine($xprojDir, "project.json")
Write-Host "Restoring $projectJsonFile"
Write-Host "dnu restore '$projectJsonFile' -s https://www.myget.org/F/nuget-volatile/api/v2/ -s https://www.nuget.org/api/v2/"
& dnu restore "$($projectJsonFile)" -s https://www.myget.org/F/nuget-volatile/api/v2/ -s https://www.nuget.org/api/v2/
if ($LASTEXITCODE -ne 0)
{
throw "Restore failed $projectJsonFile"
}
}
}
## Clean the machine level cache from all package
function CleanCache()
{
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
}
}
## Building XProj projects
function BuildXproj()
{
## Setting the DNX build version
if($ReleaseLabel -ne "Release")
{
$env:DNX_BUILD_VERSION="$ReleaseLabel-$BuildNumber"
}
# Setting the DNX AssemblyFileVersion
$env:DNX_ASSEMBLY_FILE_VERSION=$BuildNumber
if ($SkipRestore -eq $False)
{
Write-Host "Restoring XProj packages"
foreach ($file in (Get-ChildItem "src" -rec))
{
RestoreXProj($file)
}
}
$artifactsSrc = Join-Path $artifacts "src\NuGet.Core"
$artifactsTest = Join-Path $artifacts "test"
foreach ($file in (Get-ChildItem "src" -rec))
{
$ext = [System.IO.Path]::GetExtension($file.FullName)
if ($ext -eq ".xproj")
{
$srcDir = [System.IO.Path]::GetDirectoryName($file.FullName)
$outDir = Join-Path $artifacts $file.BaseName
& dnu pack "$($srcDir)" --configuration $Configuration --out $outDir
if ($LASTEXITCODE -ne 0)
{
throw "Build failed $srcDir"
}
}
}
if ($SkipTests -eq $False)
{
# Test assemblies should not be signed
if (Test-Path Env:\DNX_BUILD_KEY_FILE)
{
Remove-Item Env:\DNX_BUILD_KEY_FILE
}
if (Test-Path Env:\DNX_BUILD_DELAY_SIGN)
{
Remove-Item Env:\DNX_BUILD_DELAY_SIGN
}
foreach ($file in (Get-ChildItem "test\NuGet.Core.Tests" -rec))
{
RestoreXProj($file)
}
foreach ($file in (Get-ChildItem "test\NuGet.Core.Tests" -rec))
{
$ext = [System.IO.Path]::GetExtension($file.FullName)
if ($ext -eq ".xproj")
{
$srcDir = [System.IO.Path]::GetDirectoryName($file.FullName)
Write-Host "Running tests in $srcDir"
pushd $srcDir
& dnx test
popd
if ($LASTEXITCODE -ne 0)
{
throw "Tests failed $srcDir"
}
}
}
}
## Copying nupkgs
Write-Host "Copying the packages to" $artifactsPackages
Get-ChildItem $artifacts\*.nupkg -Recurse | % { Move-Item $_ $nupkgsDir }
}
function BuildCSproj()
{
#Building the microsoft interop package for the test.utility
$interopLib = ".\lib\Microsoft.VisualStudio.ProjectSystem.Interop"
& dnu restore $interopLib -s https://www.myget.org/F/nuget-volatile/api/v2/ -s https://www.nuget.org/api/v2/
& dnu pack $interopLib
Get-ChildItem $interopLib\*.nupkg -Recurse | % { Move-Item $_ $nupkgsDir }
# Restore packages for NuGet.Tooling solution
& $nugetExe restore -msbuildVersion 14 .\NuGet.Clients.sln
# Build the solution
& $msbuildExe .\NuGet.Clients.sln "/p:Configuration=$Configuration;ReleaseLabel=$ReleaseLabel;BuildNumber=$BuildNumber;RunTests=!$SkipTests"
if ($LASTEXITCODE -ne 0)
{
throw "NuGet.Clients.sln Build failed "
}
Write-Host "Copying the Vsix to $artifacts"
$visxLocation = Join-Path $artifacts "$Configuration\NuGet.Clients\VsExtension"
Copy-Item $visxLocation\NuGet.Tools.vsix $artifacts
}
function ILMergeNuGet()
{
$nugetArtifictFolder = Join-Path $artifacts "$Configuration\NuGet.Clients\NuGet.CommandLine"
pushd $nugetArtifictFolder
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.Credentials.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:$artifacts\NuGet.exe
if ($LASTEXITCODE -ne 0)
{
throw "ILMerge failed"
}
popd
}
###Functions###
# Move to the script directory
$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
pushd $executingScriptDirectory
$msbuildExe = "${env:ProgramFiles(x86)}\MSBuild\14.0\Bin\msbuild.exe"
$nugetExe = ".nuget\nuget.exe"
$ILMerge = Join-Path $executingScriptDirectory "packages\ILMerge.2.14.1208\tools\ILMerge.exe"
$dnvmLoc = Join-Path $env:USERPROFILE ".dnx\bin\dnvm.cmd"
$nupkgsDir = Join-Path $executingScriptDirectory "nupkgs"
$artifacts = Join-Path $executingScriptDirectory "artifacts"
$startTime = [DateTime]::UtcNow
Write-Host "Build started at " $startTime
Write-Host
if ($SkipSubModules -eq $False)
{
if ((Test-Path -Path "submodules/FileSystem/src") -eq $False)
{
Write-Host "Updating and initializing submodules"
& git submodule update --init
}
else
{
Write-Host "Updating submodules"
& git submodule update
}
}
# Download NuGet.exe if missing
if ((Test-Path $nugetExe) -eq $False)
{
Write-Host "Downloading nuget.exe"
wget https://dist.nuget.org/win-x86-commandline/latest-prerelease/nuget.exe -OutFile $nugetExe
}
# Restoring tools required for build
if ($SkipRestore -eq $False)
{
Write-Host "Restoring tools"
& $nugetExe restore .nuget\packages.config -SolutionDirectory .
}
## Validating DNVM installed and install it if missing
if ((Test-Path $dnvmLoc) -eq $False)
{
Write-Host "Downloading DNVM"
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
}
## Clean artifacts and nupkgs folder
if (Test-Path $nupkgsDir)
{
Write-Host "Cleaning nupkgs folder"
Remove-Item $nupkgsDir\*.nupkg
}
if( Test-Path $artifacts)
{
Write-Host "Cleaning the artifacts folder"
Remove-Item $artifacts\*.* -Recurse
}
## Make sure the needed DNX runtimes ex
Write-Host "Validating the correct DNX runtime set"
$env:DNX_FEED="https://www.nuget.org/api/v2"
& dnvm install 1.0.0-beta7 -runtime CoreCLR -arch x86
& dnvm install 1.0.0-beta7 -runtime CLR -arch x86 -alias default
if($CleanCache)
{
CleanCache
}
# enable delay signed build
if ($DelaySign)
{
if (Test-Path $MSPFXPath)
{
Write-Host "Setting NuGet.Core solution to delay sign using $MSPFXPath"
$env:DNX_BUILD_KEY_FILE=$MSPFXPath
$env:DNX_BUILD_DELAY_SIGN=$true
}
if (Test-Path $NuGetPFXPath)
{
Write-Host "Setting NuGet.Clients solution to delay sign using $NuGetPFXPath"
$env:NUGET_PFX_PATH= $NuGetPFXPath
Write-Host "Using the Microsoft Key for NuGet Command line $MSPFXPath"
$env:MS_PFX_PATH=$MSPFXPath
}
}
$SemanticVersionDate = "2015-10-8"
if(!$BuildNumber)
{
$R = ""
$BuildNumber = ([Math]::DivRem(([System.DateTime]::Now.Subtract([System.DateTime]::Parse($SemanticVersionDate)).TotalMinutes), 5, [ref]$R)).ToString('F0')
}
else
{
$buildNum = [int]$BuildNumber
$BuildNumber = $buildNum.ToString("D4");
}
if(!$SkipXProj)
{
## Building all XProj projects
BuildXproj
}
## Building the Tooling solution
BuildCSproj
if ($SkipILMerge -eq $False)
{
## Merging the NuGet.exe
ILMergeNuGet
}
## Calculating Build time
$endTime = [DateTime]::UtcNow
$diff = [math]::Round(($endTime - $startTime).TotalMinutes, 4)
Write-Host
Write-Host "Build ended at " $endTime
Write-Host "Build took " $diff "(mins)"
Write-Host
popd