Skip to content

Commit 04c36f5

Browse files
author
Kapil Borle
committed
Add build, restore and clean tasks
1 parent 14a36e0 commit 04c36f5

File tree

1 file changed

+76
-5
lines changed

1 file changed

+76
-5
lines changed

.build.ps1

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,80 @@ param(
66
[string]$Configuration = "Debug"
77
)
88

9-
task -Name restore `
10-
-Inputs Engine/project.json, Rules/project.json `
11-
-Outputs Engine/project.lock.json, Rules/project.lock.json `
12-
-Jobs {
13-
dotnet restore
9+
function Get-BuildInputs($project) {
10+
pushd $buildRoot/$project
11+
gci -Filter *.cs
12+
gci -Directory -Exclude obj,bin | gci -Filter *.cs -Recurse
13+
popd
1414
}
15+
16+
function Get-BuildOutputs($project) {
17+
$bin = "$buildRoot/$project/bin/$Configuration/$Framework"
18+
$obj = "$buildRoot/$project/obj/$Configuration/$Framework"
19+
if (Test-Path $bin) {
20+
gci $bin -Recurse
21+
}
22+
if (Test-Path $obj) {
23+
gci $obj -Recurse
24+
}
25+
}
26+
27+
function Get-BuildTaskParams($project) {
28+
$taskParams = @{
29+
Jobs = {dotnet build --framework $Framework --configuration $Configuration}
30+
}
31+
32+
$outputs = (Get-BuildOutputs $project)
33+
if ($null -ne $outputs) {
34+
$inputs = (Get-BuildInputs $project)
35+
$taskParams.Add("Outputs", $outputs)
36+
$taskParams.Add("Inputs", $inputs)
37+
}
38+
39+
$taskParams
40+
}
41+
42+
function Get-RestoreTaskParams($project) {
43+
@{
44+
Inputs = "$BuildRoot/$project/project.json"
45+
Outputs = "$BuildRoot/$project/project.lock.json"
46+
Jobs = {dotnet restore}
47+
}
48+
}
49+
50+
function Get-CleanTaskParams($project) {
51+
@{
52+
Jobs = {
53+
if (Test-Path obj) {
54+
Remove-Item obj -Force -Recurse
55+
}
56+
57+
if (Test-Path bin) {
58+
Remove-Item bin -Force -Recurse
59+
}
60+
}
61+
}
62+
}
63+
64+
function Add-ProjectTask([string]$project, [string]$taskName, [hashtable]$taskParams) {
65+
$jobs = [scriptblock]::Create(@"
66+
pushd $buildRoot/$project
67+
$($taskParams.Jobs)
68+
popd
69+
"@)
70+
$taskParams.Jobs = $jobs
71+
$taskParams.Name = "$project/$taskName"
72+
task @taskParams
73+
}
74+
75+
$projects = @("engine", "rules")
76+
77+
$projects | % {Add-ProjectTask $_ build (Get-BuildTaskParams $_)}
78+
task build "engine/build", "rules/build"
79+
80+
$projects | % {Add-ProjectTask $_ "restore" (Get-RestoreTaskParams $_)}
81+
task restore "engine/restore", "rules/restore"
82+
83+
$projects | % {Add-ProjectTask $_ clean (Get-CleanTaskParams $_)}
84+
task clean "engine/clean", "rules/clean"
85+

0 commit comments

Comments
 (0)