summary refs log tree commit diff
path: root/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh
blob: 3f2a89c41404483a84c21d386bfb5a8628603d5b (plain) (blame)
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
# inherit arguments from derivation
dotnetInstallFlags=( ${dotnetInstallFlags[@]-} )

dotnetInstallHook() {
    echo "Executing dotnetInstallHook"

    runHook preInstall

    if [ "${selfContainedBuild-}" ]; then
        dotnetInstallFlags+=("--self-contained")
    else
        dotnetInstallFlags+=("--no-self-contained")
        # https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained
        # Trimming is only available for self-contained build, so force disable it here
        dotnetInstallFlags+=("-p:PublishTrimmed=false")
    fi

    if [ "${useAppHost-}" ]; then
        dotnetInstallFlags+=("-p:UseAppHost=true")
    fi

    dotnetPublish() {
        local -r project="${1-}"

        runtimeIdFlags=()
        if [[ "$project" == *.csproj ]] || [ "${selfContainedBuild-}" ]; then
            runtimeIdFlags+=("--runtime @runtimeId@")
        fi

        env dotnet publish ${project-} \
            -p:ContinuousIntegrationBuild=true \
            -p:Deterministic=true \
            --output "$out/lib/${pname}" \
            --configuration "@buildType@" \
            --no-build \
            ${runtimeIdFlags[@]} \
            ${dotnetInstallFlags[@]}  \
            ${dotnetFlags[@]}
    }

    dotnetPack() {
        local -r project="${1-}"
        env dotnet pack ${project-} \
            -p:ContinuousIntegrationBuild=true \
            -p:Deterministic=true \
            --output "$out/share" \
            --configuration "@buildType@" \
            --no-build \
            --runtime "@runtimeId@" \
            ${dotnetPackFlags[@]}  \
            ${dotnetFlags[@]}
    }

    if (( "${#projectFile[@]}" == 0 )); then
        dotnetPublish
    else
        for project in ${projectFile[@]}; do
            dotnetPublish "$project"
        done
    fi

    if [[ "${packNupkg-}" ]]; then
        if (( "${#projectFile[@]}" == 0 )); then
            dotnetPack
        else
            for project in ${projectFile[@]}; do
                dotnetPack "$project"
            done
        fi
    fi

    runHook postInstall

    echo "Finished dotnetInstallHook"
}

if [[ -z "${dontDotnetInstall-}" && -z "${installPhase-}" ]]; then
    installPhase=dotnetInstallHook
fi