-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-nuget.ps1
101 lines (86 loc) · 2.95 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
param(
[Parameter(Mandatory=$false,Position=1)][bool]$installTemplates=$false
)
$scriptDir = split-path -parent $MyInvocation.MyCommand.Definition
$srcDir = (Join-Path -path $scriptDir src)
$original = (Join-Path -path $srcDir "DisCatSharpTemplates.nuspec")
$versioned = (Join-Path -path $srcDir "DisCatSharpTemplates-versioned.nuspec")
$tag = Get-Content -Path (Join-Path -path $scriptDir "version.txt")
Write-Host "Using Git Tag: $tag ..."
# nuget.exe needs to be on the path or aliased
function Reset-Templates{
[cmdletbinding()]
param(
[string]$templateEngineUserDir = (join-path -Path $env:USERPROFILE -ChildPath .templateengine)
)
process{
'resetting dotnet new templates. folder: "{0}"' -f $templateEngineUserDir | Write-host
get-childitem -path $templateEngineUserDir -directory | Select-Object -ExpandProperty FullName | remove-item -recurse
&dotnet new --debug:reinit
}
}
function Clean(){
[cmdletbinding()]
param(
[string]$rootFolder = $scriptDir
)
process{
'clean started, rootFolder "{0}"' -f $rootFolder | write-host
# delete folders that should not be included in the nuget package
Get-ChildItem -path $rootFolder -include bin,obj,nupkg -Recurse -Directory | Select-Object -ExpandProperty FullName | Remove-item -recurse
}
}
function SetupNuspec(){
Write-Host "Version in Nuspec: $tag"
if (Test-Path -LiteralPath $versioned)
{
Write-Host "Removing Old $versioned..."
Remove-Item -Recurse -Force $versioned
}
Copy-Item -Path $original -Destination $versioned
(Get-Content $versioned).replace('%VERSION%', $tag) | Set-Content $versioned
}
function ResetSpec(){
if (Test-Path -LiteralPath $versioned)
{
Write-Host "Removing Old $versioned..."
Remove-Item -Recurse -Force $versioned
}
}
# we need to ensure our solution template is generated / updated prior to final package
if($IsLinux)
{
Start-Process pwsh "$scriptDir/update-solution-template.ps1"
}
else
{
Start-Process powershell "$scriptDir/update-solution-template.ps1"
}
# start script
Clean
SetupNuspec
# create nuget package
$outputpath = Join-Path $scriptDir nupkg
if(Test-Path $versioned){
./nuget.exe pack $versioned -OutputDirectory $outputpath
}
else{
'ERROR: nuspec file not found at {0}' -f $versioned | Write-Error
return
}
# If the user wants to install the templates they must pass in a true value
if($installTemplates){
$item = Get-ChildItem -Path "$scriptDir/nupkg" -File -Filter *.nupkg
# install nuget package using dotnet new --install
if($item){
$name = $item.Name
$pathtonupkg = join-path $scriptDir "nupkg/$name"
Reset-Templates
'installing template with command "dotnet new --install {0}"' -f $pathtonupkg | write-host
&dotnet new --install $pathtonupkg
}
else{
'Not installing template because it was not found at "{0}"' -f $pathtonupkg | Write-Error
}
}
ResetSpec