-
Notifications
You must be signed in to change notification settings - Fork 9
/
build-nuget.ps1
52 lines (47 loc) · 1.7 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
$scriptDir = split-path -parent $MyInvocation.MyCommand.Definition
$srcDir = (Join-Path -path $scriptDir src)
# 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
}
}
# start script
Clean
# create nuget package
$outputpath = Join-Path $scriptDir nupkg
$pathtonuspec = Join-Path $srcDir templates.nuspec
if(Test-Path $pathtonuspec){
nuget.exe pack $pathtonuspec -OutputDirectory $outputpath
}
else{
'ERROR: nuspec file not found at {0}' -f $pathtonuspec | Write-Error
return
}
$pathtonupkg = join-path $scriptDir nupkg/Masa.Template.1.0.0.nupkg
# install nuget package using dotnet new install
if(test-path $pathtonupkg){
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
}