-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.ps1
55 lines (45 loc) · 1.38 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
[CmdletBinding()]
param (
[Parameter(HelpMessage = "The action to execute.")]
[ValidateSet("Build", "Test", "Pack")]
[string] $Action = "Build",
[Parameter(HelpMessage = "The msbuild configuration to use.")]
[ValidateSet("Debug", "Release")]
[string] $Configuration = "Debug",
[Parameter(HelpMessage = "The project to reference.")]
[string] $Project,
[switch] $NoRestore,
[switch] $Clean
)
function RunCommand {
param ([string] $CommandExpr)
Write-Verbose " $CommandExpr"
Invoke-Expression $CommandExpr
}
$rootDir = $PSScriptRoot
$actionDir = $rootDir
switch ($Action) {
{ "Pack", "Test" -eq $_ } {
if (!$Project) {
Write-Error "The project parameter is required when packing."
exit 1
}
$actionDir = Join-Path -Path $rootDir -ChildPath $Project
}
Default {
if ($Project) {
$actionDir = Join-Path -Path $rootDir -ChildPath $Project
}
}
}
if (!$NoRestore.IsPresent) {
RunCommand "dotnet restore $actionDir --force --force-evaluate --no-cache --nologo --verbosity quiet"
}
if ($Clean) {
RunCommand "dotnet clean $actionDir -c $Configuration --nologo --verbosity quiet"
}
switch ($Action) {
"Test" { RunCommand "dotnet test `"$actionDir`"" }
"Pack" { RunCommand "dotnet pack `"$actionDir`" -c $Configuration --include-symbols --include-source" }
Default { RunCommand "dotnet build `"$actionDir`" -c $Configuration" }
}