-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
/
Copy pathdotnet-build-hook.sh
89 lines (73 loc) · 2.81 KB
/
dotnet-build-hook.sh
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
dotnetBuildHook() {
echo "Executing dotnetBuildHook"
runHook preBuild
local -r dotnetBuildType="${dotnetBuildType-Release}"
if [[ -n $__structuredAttrs ]]; then
local dotnetProjectFilesArray=( "${dotnetProjectFiles[@]}" )
local dotnetTestProjectFilesArray=( "${dotnetTestProjectFiles[@]}" )
local dotnetFlagsArray=( "${dotnetFlags[@]}" )
local dotnetBuildFlagsArray=( "${dotnetBuildFlags[@]}" )
local dotnetRuntimeIdsArray=( "${dotnetRuntimeIds[@]}" )
else
local dotnetProjectFilesArray=($dotnetProjectFiles)
local dotnetTestProjectFilesArray=($dotnetTestProjectFiles)
local dotnetFlagsArray=($dotnetFlags)
local dotnetBuildFlagsArray=($dotnetBuildFlags)
local dotnetRuntimeIdsArray=($dotnetRuntimeIds)
fi
if [[ -n "${enableParallelBuilding-}" ]]; then
local -r maxCpuFlag="$NIX_BUILD_CORES"
local -r parallelBuildFlag="true"
else
local -r maxCpuFlag="1"
local -r parallelBuildFlag="false"
fi
if [[ -n ${dotnetSelfContainedBuild-} ]]; then
dotnetBuildFlagsArray+=("-p:SelfContained=true")
else
dotnetBuildFlagsArray+=("-p:SelfContained=false")
fi
if [[ -n ${dotnetUseAppHost-} ]]; then
dotnetBuildFlagsArray+=("-p:UseAppHost=true")
fi
local versionFlagsArray=()
if [[ -n ${version-} ]]; then
versionFlagsArray+=("-p:InformationalVersion=$version")
fi
if [[ -n ${versionForDotnet-} ]]; then
versionFlagsArray+=("-p:Version=$versionForDotnet")
fi
dotnetBuild() {
local -r projectFile="${1-}"
for runtimeId in "${dotnetRuntimeIdsArray[@]}"; do
local runtimeIdFlagsArray=()
if [[ $projectFile == *.csproj || -n ${dotnetSelfContainedBuild-} ]]; then
runtimeIdFlagsArray+=("--runtime" "$runtimeId")
fi
dotnet build ${1+"$projectFile"} \
-maxcpucount:"$maxCpuFlag" \
-p:BuildInParallel="$parallelBuildFlag" \
-p:ContinuousIntegrationBuild=true \
-p:Deterministic=true \
-p:OverwriteReadOnlyFiles=true \
--configuration "$dotnetBuildType" \
--no-restore \
"${versionFlagsArray[@]}" \
"${runtimeIdFlagsArray[@]}" \
"${dotnetBuildFlagsArray[@]}" \
"${dotnetFlagsArray[@]}"
done
}
if (( ${#dotnetProjectFilesArray[@]} == 0 )); then
dotnetBuild
fi
local projectFile
for projectFile in "${dotnetProjectFilesArray[@]}" "${dotnetTestProjectFilesArray[@]}"; do
dotnetBuild "$projectFile"
done
runHook postBuild
echo "Finished dotnetBuildHook"
}
if [[ -z ${dontDotnetBuild-} && -z ${buildPhase-} ]]; then
buildPhase=dotnetBuildHook
fi