-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build-NugetCache.ps1
72 lines (55 loc) · 1.76 KB
/
Build-NugetCache.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
param(
[PSObject]
[Parameter(Mandatory)]
$Config
)
function Add-ProjectDependency([string] $dependency, [string] $output) {
if ($dependency.Contains('@')) {
$split = $dependency.Split('@')
$dependency = $split[0]
$version = $split[1]
& dotnet add $output package $dependency --version $version
}
else {
if ($dependency.EndsWith('!')) {
& dotnet add $output package $($dependency.Replace('!', '')) --prerelease
}
else {
& dotnet add $output package $dependency
}
}
}
function Build-Project([psobject] $project, [string] $sln) {
$output = Join-Path $sln $project.name
& dotnet new $project.template -o $output -f $project.framework
& dotnet sln $sln add $output
$project.dependencies | ForEach-Object {
Add-ProjectDependency $_ $output
}
}
function Build-Solution([psobject] $projects, [string] $sln) {
& dotnet new sln -o $sln
$projects | ForEach-Object {
Build-Project $_ $sln
}
}
function Build-Cache([string] $cache, [string] $sln) {
if (-not (Test-Path $cache)) {
New-Item -Path $cache -ItemType Directory -Force
}
& dotnet restore $sln --packages $cache
}
Write-Host "Generating NuGet cache..." -ForegroundColor Blue
$sln = Join-Path $Config.target $Config.data.solution
if (Test-Path $sln) {
Remove-Item $sln -Recurse -Force
}
Build-Solution $Config.data.projects $sln
if ($Config.data.clean) {
& dotnet nuget locals all --clear
}
Build-Cache $Config.target $sln
if (-not $Config.data.keep) {
Remove-Item $sln -Recurse -Force
}
Write-Host "NuGet cache successfully generated!" -ForegroundColor Green