-
Notifications
You must be signed in to change notification settings - Fork 0
/
include.ps1
102 lines (76 loc) · 2.72 KB
/
include.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
function Check-ExitCode() {
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
Write-Output "Non-zero ($exitCode) exit code. Exiting..."
exit $exitCode
}
}
function GetStringBetweenTwoStrings($firstString, $secondString, $importPath) {
$file = Get-Content $importPath
$pattern = "$firstString(.*?)$secondString"
$result = [regex]::Match($file, $pattern).Groups[1].Value
return $result
}
function Clean() {
if (Test-Path $outDir) {
Remove-Item -Force -Recurse $outDir
}
mkdir $outDir | Out-Null
}
function Build() {
dotnet clean "$baseDir/EFrt.sln" --configuration $Configuration
Check-ExitCode
dotnet build "$baseDir/EFrt.sln" --configuration $Configuration --configfile "$baseDir/NuGet.Config" --force --no-cache --verbosity minimal
Check-ExitCode
}
function BuildProject($projectName, $cleanUp=$False) {
Set-Location $projectName
if ($cleanUp) {
Write-Host "Cleaning..."
dotnet clean --configuration $Configuration --verbosity normal
Check-ExitCode
}
dotnet build --configuration $Configuration --configfile "$baseDir/NuGet.Config" --force --no-cache --verbosity normal
Check-ExitCode
Set-Location $baseDir
}
# Note: Call the Build function before this!
function PackProject($projectName, $cleanUp=$True, $useMonoToRunNuget=$False) {
Write-Host "Packing project:" $projectName
Set-Location $projectName
$packageVersion = GetStringBetweenTwoStrings -firstString "<Version>" -secondString "</Version>" -importPath "$baseDir/$projectName/$projectName.csproj"
Check-ExitCode
Write-Host "Package version: " + $packageVersion
dotnet pack --configuration $Configuration --no-restore --force -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --output $outDir --verbosity minimal
Check-ExitCode
if ($cleanUp) {
Write-Host "Removing the previous build of this package version..."
# This can fail.
if ($useMonoToRunNuget)
{
& mono $nugetPath delete $projectName $packageVersion -noninteractive -source $nugetDir
}
else
{
& $nugetPath delete $projectName $packageVersion -noninteractive -source $nugetDir
}
Write-Host "Previous package build removed."
}
# If the cleanup fails, it sets the exit code to 1.
# This will reset the exit code to 0, so the next Check-ExitCode
# command won't detect this fail, that is not related to
# the nuget add command below, as its failure.
$LASTEXITCODE = 0
Write-Host "Adding the package to the local NuGet repository..."
if ($useMonoToRunNuget)
{
& mono $nugetPath add "$outDir/$projectName.$packageVersion.nupkg" -source $nugetDir
}
else
{
& $nugetPath add "$outDir/$projectName.$packageVersion.nupkg" -source $nugetDir
}
Check-ExitCode
Write-Host "Package added."
Set-Location $baseDir
}