about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2022-09-26 18:01:53 +0000
committerGitHub <noreply@github.com>2022-09-26 18:01:53 +0000
commit59a37c822b7d029047a46587460b37d0a4caf6f1 (patch)
treedd26d028977e12e91aeb781e5b6522d71f3ceae6 /pkgs/build-support
parent4a7456943a79e2449977e353d53c827cb69ba914 (diff)
parent4a1de73b6894dfcdcac298147b105d34e8c3ddb4 (diff)
downloadnixlib-59a37c822b7d029047a46587460b37d0a4caf6f1.tar
nixlib-59a37c822b7d029047a46587460b37d0a4caf6f1.tar.gz
nixlib-59a37c822b7d029047a46587460b37d0a4caf6f1.tar.bz2
nixlib-59a37c822b7d029047a46587460b37d0a4caf6f1.tar.lz
nixlib-59a37c822b7d029047a46587460b37d0a4caf6f1.tar.xz
nixlib-59a37c822b7d029047a46587460b37d0a4caf6f1.tar.zst
nixlib-59a37c822b7d029047a46587460b37d0a4caf6f1.zip
Merge master into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/default.nix309
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh42
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh10
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh26
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh25
-rw-r--r--pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh60
6 files changed, 270 insertions, 202 deletions
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/default.nix b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
index 470d2d47ff94..b65aecd7e05c 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/default.nix
+++ b/pkgs/build-support/dotnet/build-dotnet-module/default.nix
@@ -1,18 +1,18 @@
 { lib
 , stdenvNoCC
 , callPackage
+, writeShellScript
+, writeText
+, srcOnly
 , linkFarmFromDrvs
+, symlinkJoin
+, makeWrapper
 , dotnetCorePackages
 , dotnetPackages
 , mkNugetSource
 , mkNugetDeps
-, srcOnly
-, writeShellScript
-, writeText
-, makeWrapper
 , nuget-to-nix
 , cacert
-, symlinkJoin
 , coreutils
 }:
 
@@ -20,88 +20,87 @@
 , pname ? name
 , enableParallelBuilding ? true
 , doCheck ? false
-# Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
-, makeWrapperArgs ? []
-
-# Flags to pass to `dotnet restore`.
-, dotnetRestoreFlags ? []
-# Flags to pass to `dotnet build`.
-, dotnetBuildFlags ? []
-# Flags to pass to `dotnet test`, if running tests is enabled.
-, dotnetTestFlags ? []
-# Flags to pass to `dotnet install`.
-, dotnetInstallFlags ? []
-# Flags to pass to `dotnet pack`.
-, dotnetPackFlags ? []
-# Flags to pass to dotnet in all phases.
-, dotnetFlags ? []
-
-# The path to publish the project to. When unset, the directory "$out/lib/$pname" is used.
+  # Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
+, makeWrapperArgs ? [ ]
+
+  # Flags to pass to `dotnet restore`.
+, dotnetRestoreFlags ? [ ]
+  # Flags to pass to `dotnet build`.
+, dotnetBuildFlags ? [ ]
+  # Flags to pass to `dotnet test`, if running tests is enabled.
+, dotnetTestFlags ? [ ]
+  # Flags to pass to `dotnet install`.
+, dotnetInstallFlags ? [ ]
+  # Flags to pass to `dotnet pack`.
+, dotnetPackFlags ? [ ]
+  # Flags to pass to dotnet in all phases.
+, dotnetFlags ? [ ]
+
+  # The path to publish the project to. When unset, the directory "$out/lib/$pname" is used.
 , installPath ? null
-# The binaries that should get installed to `$out/bin`, relative to `$out/lib/$pname/`. These get wrapped accordingly.
-# Unfortunately, dotnet has no method for doing this automatically.
-# If unset, all executables in the projects root will get installed. This may cause bloat!
+  # The binaries that should get installed to `$out/bin`, relative to `$out/lib/$pname/`. These get wrapped accordingly.
+  # Unfortunately, dotnet has no method for doing this automatically.
+  # If unset, all executables in the projects root will get installed. This may cause bloat!
 , executables ? null
-# Packs a project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`.
+  # Packs a project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`.
 , packNupkg ? false
-# The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well.
+  # The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well.
 , projectFile ? null
-# The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
-# This can be generated by running the `passthru.fetch-deps` script.
+  # The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched.
+  # This can be generated by running the `passthru.fetch-deps` script.
 , nugetDeps ? null
-# A list of derivations containing nupkg packages for local project references.
-# Referenced derivations can be built with `buildDotnetModule` with `packNupkg=true` flag.
-# Since we are sharing them as nugets they must be added to csproj/fsproj files as `PackageReference` as well.
-# For example, your project has a local dependency:
-#     <ProjectReference Include="../foo/bar.fsproj" />
-# To enable discovery through `projectReferences` you would need to add a line:
-#     <ProjectReference Include="../foo/bar.fsproj" />
-#     <PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/>
-, projectReferences ? []
-# Libraries that need to be available at runtime should be passed through this.
-# These get wrapped into `LD_LIBRARY_PATH`.
-, runtimeDeps ? []
-
-# Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
-# See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
-, disabledTests ? []
-# The project file to run unit tests against. This is usually referenced in the regular project file, but sometimes it needs to be manually set.
-# It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
+  # A list of derivations containing nupkg packages for local project references.
+  # Referenced derivations can be built with `buildDotnetModule` with `packNupkg=true` flag.
+  # Since we are sharing them as nugets they must be added to csproj/fsproj files as `PackageReference` as well.
+  # For example, your project has a local dependency:
+  #     <ProjectReference Include="../foo/bar.fsproj" />
+  # To enable discovery through `projectReferences` you would need to add a line:
+  #     <ProjectReference Include="../foo/bar.fsproj" />
+  #     <PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/>
+, projectReferences ? [ ]
+  # Libraries that need to be available at runtime should be passed through this.
+  # These get wrapped into `LD_LIBRARY_PATH`.
+, runtimeDeps ? [ ]
+
+  # Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks.
+  # See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details.
+, disabledTests ? [ ]
+  # The project file to run unit tests against. This is usually referenced in the regular project file, but sometimes it needs to be manually set.
+  # It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this.
 , testProjectFile ? ""
 
-# The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc.
+  # The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc.
 , buildType ? "Release"
-# If set to true, builds the application as a self-contained - removing the runtime dependency on dotnet
+  # If set to true, builds the application as a self-contained - removing the runtime dependency on dotnet
 , selfContainedBuild ? false
-# The dotnet SDK to use.
+  # The dotnet SDK to use.
 , dotnet-sdk ? dotnetCorePackages.sdk_6_0
-# The dotnet runtime to use.
+  # The dotnet runtime to use.
 , dotnet-runtime ? dotnetCorePackages.runtime_6_0
-# The dotnet SDK to run tests against. This can differentiate from the SDK compiled against.
+  # The dotnet SDK to run tests against. This can differentiate from the SDK compiled against.
 , dotnet-test-sdk ? dotnet-sdk
-, ... } @ args:
-
-assert projectFile == null -> throw "Defining the `projectFile` attribute is required. This is usually an `.csproj`, or `.sln` file.";
-
-# TODO: Automatically generate a dependency file when a lockfile is present.
-# This file is unfortunately almost never present, as Microsoft recommands not to push this in upstream repositories.
-assert nugetDeps == null -> throw "Defining the `nugetDeps` attribute is required, as to lock the NuGet dependencies. This file can be generated by running the `passthru.fetch-deps` script.";
+, ...
+} @ args:
 
 let
   inherit (callPackage ./hooks {
     inherit dotnet-sdk dotnet-test-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType;
   }) dotnetConfigureHook dotnetBuildHook dotnetCheckHook dotnetInstallHook dotnetFixupHook;
 
-  localDeps = if (projectReferences != [])
+  localDeps =
+    if (projectReferences != [ ])
     then linkFarmFromDrvs "${name}-project-references" projectReferences
     else null;
 
-  _nugetDeps = if lib.isDerivation nugetDeps
-    then nugetDeps
-    else mkNugetDeps { inherit name; nugetDeps = import nugetDeps; };
+  _nugetDeps =
+    if (nugetDeps != null) then
+      if lib.isDerivation nugetDeps
+      then nugetDeps
+      else mkNugetDeps { inherit name; nugetDeps = import nugetDeps; }
+    else throw "Defining the `nugetDeps` attribute is required, as to lock the NuGet dependencies. This file can be generated by running the `passthru.fetch-deps` script.";
 
   # contains the actual package dependencies
-  _dependenciesSource = mkNugetSource {
+  dependenciesSource = mkNugetSource {
     name = "${name}-dependencies-source";
     description = "A Nuget source with the dependencies for ${name}";
     deps = [ _nugetDeps ] ++ lib.optional (localDeps != null) localDeps;
@@ -110,22 +109,23 @@ let
   # this contains all the nuget packages that are implictly referenced by the dotnet
   # build system. having them as separate deps allows us to avoid having to regenerate
   # a packages dependencies when the dotnet-sdk version changes
-  _sdkDeps = mkNugetDeps {
+  sdkDeps = mkNugetDeps {
     name = "dotnet-sdk-${dotnet-sdk.version}-deps";
     nugetDeps = dotnet-sdk.passthru.packages;
   };
 
-  _sdkSource = mkNugetSource {
+  sdkSource = mkNugetSource {
     name = "dotnet-sdk-${dotnet-sdk.version}-source";
-    deps = [ _sdkDeps ];
+    deps = [ sdkDeps ];
   };
 
   nuget-source = symlinkJoin {
     name = "${name}-nuget-source";
-    paths = [ _dependenciesSource _sdkSource ];
+    paths = [ dependenciesSource sdkSource ];
   };
-in stdenvNoCC.mkDerivation (args // {
-  nativeBuildInputs = args.nativeBuildInputs or [] ++ [
+in
+stdenvNoCC.mkDerivation (args // {
+  nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
     dotnetConfigureHook
     dotnetBuildHook
     dotnetCheckHook
@@ -150,74 +150,109 @@ in stdenvNoCC.mkDerivation (args // {
   passthru = {
     inherit nuget-source;
 
-    fetch-deps = let
-      # Because this list is rather long its put in its own store path to maintain readability of the generated script
-      exclusions = writeText "nuget-package-exclusions" (lib.concatStringsSep "\n" (dotnet-sdk.passthru.packages { fetchNuGet = attrs: attrs.pname; }));
-
-      runtimeIds = map (system: dotnet-sdk.systemToDotnetRid system) (args.meta.platforms or dotnet-sdk.meta.platforms);
-
-      # Derivations may set flags such as `--runtime <rid>` based on the host platform to avoid restoring/building nuget dependencies they dont have or dont need.
-      # This introduces an issue; In this script we loop over all platforms from `meta` and add the RID flag for it, as to fetch all required dependencies.
-      # The script would inherit the RID flag from the derivation based on the platform building the script, and set the flag for any iteration we do over the RIDs.
-      # That causes conflicts. To circumvent it we remove all occurances of the flag.
-      flags =
-        let
-          hasRid = flag: lib.any (v: v) (map (rid: lib.hasInfix rid flag) (lib.attrValues dotnet-sdk.runtimeIdentifierMap));
-        in
-        builtins.filter (flag: !(hasRid flag)) (dotnetFlags ++ dotnetRestoreFlags);
-
-    in writeShellScript "fetch-${pname}-deps" ''
-      set -euo pipefail
-
-      export PATH="${lib.makeBinPath [ coreutils dotnet-sdk nuget-to-nix ]}"
-
-      case "''${1-}" in
-          --help|-h)
-              echo "usage: $0 <output path> [--help]"
-              echo "    <output path>  The path to write the lockfile to"
-              echo "    --help         Show this help message"
-              exit
-              ;;
-      esac
-
-      deps_file="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")"
-      export HOME=$(mktemp -td "${pname}-home-XXXXXX")
-      mkdir -p "$HOME/nuget_pkgs"
-
-      store_src="${srcOnly args}"
-      src="$(mktemp -td "${pname}-src-XXXXXX")"
-      cp -rT "$store_src" "$src"
-      chmod -R +w "$src"
-      trap "rm -rf $src $HOME" EXIT
-
-      cd "$src"
-      echo "Restoring project..."
-
-      export DOTNET_NOLOGO=1
-      export DOTNET_CLI_TELEMETRY_OPTOUT=1
-
-      for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do
-          for project in "${lib.concatStringsSep "\" \"" ((lib.toList projectFile) ++ lib.optionals (testProjectFile != "") (lib.toList testProjectFile))}"; do
-              dotnet restore "$project" \
-                  -p:ContinuousIntegrationBuild=true \
-                  -p:Deterministic=true \
-                  --packages "$HOME/nuget_pkgs" \
-                  --runtime "$rid" \
-                  ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
-                  ${lib.optionalString (flags != []) (toString flags)}
-          done
-      done
-
-      echo "Succesfully restored project"
-
-      echo "Writing lockfile..."
-      echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$deps_file"
-      nuget-to-nix "$HOME/nuget_pkgs" "${exclusions}" >> "$deps_file"
-      echo "Succesfully wrote lockfile to: $deps_file"
-    '';
-  } // args.passthru or {};
+    fetch-deps =
+      let
+        # Because this list is rather long its put in its own store path to maintain readability of the generated script
+        exclusions = writeText "nuget-package-exclusions" (lib.concatStringsSep "\n" (dotnet-sdk.passthru.packages { fetchNuGet = attrs: attrs.pname; }));
+
+        # Derivations may set flags such as `--runtime <rid>` based on the host platform to avoid restoring/building nuget dependencies they dont have or dont need.
+        # This introduces an issue; In this script we loop over all platforms from `meta` and add the RID flag for it, as to fetch all required dependencies.
+        # The script would inherit the RID flag from the derivation based on the platform building the script, and set the flag for any iteration we do over the RIDs.
+        # That causes conflicts. To circumvent it we remove all occurances of the flag.
+        flags =
+          let
+            hasRid = flag: lib.any (v: v) (map (rid: lib.hasInfix rid flag) (lib.attrValues dotnet-sdk.runtimeIdentifierMap));
+          in
+          builtins.filter (flag: !(hasRid flag)) (dotnetFlags ++ dotnetRestoreFlags);
+
+        runtimeIds = map (system: dotnet-sdk.systemToDotnetRid system) (args.meta.platforms or dotnet-sdk.meta.platforms);
+      in
+      writeShellScript "fetch-${pname}-deps" ''
+        set -euo pipefail
+
+        export PATH="${lib.makeBinPath [ coreutils dotnet-sdk nuget-to-nix ]}"
+
+        for arg in "$@"; do
+            case "$arg" in
+                --keep-sources|-k)
+                    keepSources=1
+                    shift
+                    ;;
+                --help|-h)
+                    echo "usage: $0 <output path> [--keep-sources] [--help]"
+                    echo "    <output path>   The path to write the lockfile to. A temporary file is used if this is not set"
+                    echo "    --keep-sources  Dont remove temporary directories upon exit, useful for debugging"
+                    echo "    --help          Show this help message"
+                    exit
+                    ;;
+            esac
+        done
+
+        exitTrap() {
+            test -n "''${ranTrap-}" && return
+            ranTrap=1
+
+            if test -n "''${keepSources-}"; then
+                echo -e "Path to the source: $src\nPath to the fake home: $HOME"
+            else
+                rm -rf "$src" "$HOME"
+            fi
+
+            # Since mktemp is used this will be empty if the script didnt succesfully complete
+            ! test -s "$depsFile" && rm -rf "$depsFile"
+        }
+
+        trap exitTrap EXIT INT TERM
+
+        dotnetRestore() {
+            local -r project="''${1-}"
+            local -r rid="$2"
+
+            dotnet restore ''${project-} \
+                -p:ContinuousIntegrationBuild=true \
+                -p:Deterministic=true \
+                --packages "$HOME/nuget_pkgs" \
+                --runtime "$rid" \
+                ${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
+                ${lib.optionalString (flags != []) (toString flags)}
+        }
+
+        declare -a projectFiles=( ${toString (lib.toList projectFile)} )
+        declare -a testProjectFiles=( ${toString (lib.toList testProjectFile)} )
+
+        export HOME=$(mktemp -td "${pname}-home-XXXXXX")
+        export DOTNET_NOLOGO=1
+        export DOTNET_CLI_TELEMETRY_OPTOUT=1
+
+        depsFile="$(realpath "''${1:-$(mktemp -t "${pname}-deps-XXXXXX.nix")}")"
+        mkdir -p "$HOME/nuget_pkgs"
+
+        storeSrc="${srcOnly args}"
+        src="$(mktemp -td "${pname}-src-XXXXXX")"
+        cp -rT "$storeSrc" "$src"
+        chmod -R +w "$src"
+
+        cd "$src"
+        echo "Restoring project..."
+
+        for rid in "${lib.concatStringsSep "\" \"" runtimeIds}"; do
+            (( ''${#projectFiles[@]} == 0 )) && dotnetRestore "" "$rid"
+
+            for project in ''${projectFiles[@]-} ''${testProjectFiles[@]-}; do
+                dotnetRestore "$project" "$rid"
+            done
+        done
+
+        echo "Succesfully restored project"
+
+        echo "Writing lockfile..."
+        echo -e "# This file was automatically generated by passthru.fetch-deps.\n# Please dont edit it manually, your changes might get overwritten!\n" > "$depsFile"
+        nuget-to-nix "$HOME/nuget_pkgs" "${exclusions}" >> "$depsFile"
+        echo "Succesfully wrote lockfile to $depsFile"
+      '';
+  } // args.passthru or { };
 
   meta = {
     platforms = dotnet-sdk.meta.platforms;
-  } // args.meta or {};
+  } // args.meta or { };
 })
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh
index c7a6d8c17aba..9199b8d02a81 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-build-hook.sh
@@ -7,11 +7,11 @@ dotnetBuildHook() {
     runHook preBuild
 
     if [ "${enableParallelBuilding-}" ]; then
-        maxCpuFlag="$NIX_BUILD_CORES"
-        parallelBuildFlag="true"
+        local -r maxCpuFlag="$NIX_BUILD_CORES"
+        local -r parallelBuildFlag="true"
     else
-        maxCpuFlag="1"
-        parallelBuildFlag="false"
+        local -r maxCpuFlag="1"
+        local -r parallelBuildFlag="false"
     fi
 
     if [ "${selfContainedBuild-}" ]; then
@@ -21,22 +21,28 @@ dotnetBuildHook() {
     fi
 
     if [ "${version-}" ]; then
-        versionFlag="-p:Version=${version-}"
+        local -r versionFlag="-p:Version=${version-}"
     fi
 
-    for project in ${projectFile[@]} ${testProjectFile[@]}; do
-        env \
-            dotnet build "$project" \
-                -maxcpucount:$maxCpuFlag \
-                -p:BuildInParallel=$parallelBuildFlag \
-                -p:ContinuousIntegrationBuild=true \
-                -p:Deterministic=true \
-                -p:UseAppHost=true \
-                --configuration "@buildType@" \
-                --no-restore \
-                ${versionFlag-} \
-                ${dotnetBuildFlags[@]}  \
-                ${dotnetFlags[@]}
+    dotnetBuild() {
+        local -r project="${1-}"
+        env dotnet build ${project-} \
+            -maxcpucount:$maxCpuFlag \
+            -p:BuildInParallel=$parallelBuildFlag \
+            -p:ContinuousIntegrationBuild=true \
+            -p:Deterministic=true \
+            -p:UseAppHost=true \
+            --configuration "@buildType@" \
+            --no-restore \
+            ${versionFlag-} \
+            ${dotnetBuildFlags[@]}  \
+            ${dotnetFlags[@]}
+    }
+
+    (( "${#projectFile[@]}" == 0 )) && dotnetBuild
+
+    for project in ${projectFile[@]} ${testProjectFile[@]-}; do
+        dotnetBuild "$project"
     done
 
     runHook postBuild
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
index bc7b1b5c3d82..0c0e5d310eab 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-check-hook.sh
@@ -7,10 +7,16 @@ dotnetCheckHook() {
     runHook preCheck
 
     if [ "${disabledTests-}" ]; then
-        disabledTestsFlag="--filter FullyQualifiedName!=@disabledTests@"
+        local -r disabledTestsFlag="--filter FullyQualifiedName!=@disabledTests@"
     fi
 
-    for project in ${testProjectFile[@]}; do
+    if [ "${enableParallelBuilding-}" ]; then
+        local -r maxCpuFlag="$NIX_BUILD_CORES"
+    else
+        local -r maxCpuFlag="1"
+    fi
+
+    for project in ${testProjectFile[@]-}; do
         env "LD_LIBRARY_PATH=@libraryPath@" \
             dotnet test "$project" \
               -maxcpucount:$maxCpuFlag \
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh
index 3e8c14189500..10067cf08824 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-configure-hook.sh
@@ -10,18 +10,24 @@ dotnetConfigureHook() {
     runHook preConfigure
 
     if [ -z "${enableParallelBuilding-}" ]; then
-        parallelFlag="--disable-parallel"
+        local -r parallelFlag="--disable-parallel"
     fi
 
-    for project in ${projectFile[@]} ${testProjectFile[@]}; do
-        env \
-            dotnet restore "$project" \
-                -p:ContinuousIntegrationBuild=true \
-                -p:Deterministic=true \
-                --source "@nugetSource@/lib" \
-                ${parallelFlag-} \
-                ${dotnetRestoreFlags[@]} \
-                ${dotnetFlags[@]}
+    dotnetRestore() {
+        local -r project="${1-}"
+        env dotnet restore ${project-} \
+            -p:ContinuousIntegrationBuild=true \
+            -p:Deterministic=true \
+            --source "@nugetSource@/lib" \
+            ${parallelFlag-} \
+            ${dotnetRestoreFlags[@]} \
+            ${dotnetFlags[@]}
+    }
+
+    (( "${#projectFile[@]}" == 0 )) && dotnetRestore
+
+    for project in ${projectFile[@]} ${testProjectFile[@]-}; do
+        dotnetRestore "$project"
     done
 
     runHook postConfigure
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh
index 0a881fae9cfa..59df9b319afb 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-fixup-hook.sh
@@ -5,38 +5,37 @@ makeWrapperArgs=( ${makeWrapperArgs-} )
 # the second is the destination for the wrapper.
 wrapDotnetProgram() {
     if [ ! "${selfContainedBuild-}" ]; then
-        dotnetRootFlag=("--set" "DOTNET_ROOT" "@dotnetRuntime@")
+        local -r dotnetRootFlag=("--set" "DOTNET_ROOT" "@dotnetRuntime@")
     fi
 
     makeWrapper "$1" "$2" \
-        "${dotnetRootFlag[@]}" \
         --suffix "LD_LIBRARY_PATH" : "@runtimeDeps@" \
+        "${dotnetRootFlag[@]}" \
         "${gappsWrapperArgs[@]}" \
         "${makeWrapperArgs[@]}"
 
-    echo "Installed wrapper to: "$2""
+    echo "installed wrapper to "$2""
 }
 
 dotnetFixupHook() {
     echo "Executing dotnetFixupPhase"
 
-    if [ "${executables}" ]; then
+    if [ "${executables-}" ]; then
         for executable in ${executables[@]}; do
-            execPath="$out/lib/${pname}/$executable"
+            path="$out/lib/$pname/$executable"
 
-            if [[ -f "$execPath" && -x "$execPath" ]]; then
-                wrapDotnetProgram "$execPath" "$out/bin/$(basename "$executable")"
+            if test -x "$path"; then
+                wrapDotnetProgram "$path" "$out/bin/$(basename "$executable")"
             else
-                echo "Specified binary \"$executable\" is either not an executable, or does not exist!"
+                echo "Specified binary \"$executable\" is either not an executable or does not exist!"
+                echo "Looked in $path"
                 exit 1
             fi
         done
     else
-        for executable in $out/lib/${pname}/*; do
-            if [[ -f "$executable" && -x "$executable" && "$executable" != *"dll"* ]]; then
-                wrapDotnetProgram "$executable" "$out/bin/$(basename "$executable")"
-            fi
-        done
+        while IFS= read -d '' executable; do
+            wrapDotnetProgram "$executable" "$out/bin/$(basename "$executable")" \;
+        done < <(find "$out/lib/$pname" ! -name "*.dll" -executable -type f -print0)
     fi
 
     echo "Finished dotnetFixupPhase"
diff --git a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh
index fd88ea32ec04..217e79e41b46 100644
--- a/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh
+++ b/pkgs/build-support/dotnet/build-dotnet-module/hooks/dotnet-install-hook.sh
@@ -12,33 +12,49 @@ dotnetInstallHook() {
         dotnetInstallFlags+=("--no-self-contained")
     fi
 
-    for project in ${projectFile[@]}; do
-        env \
-            dotnet publish "$project" \
-                -p:ContinuousIntegrationBuild=true \
-                -p:Deterministic=true \
-                -p:UseAppHost=true \
-                --output "$out/lib/${pname}" \
-                --configuration "@buildType@" \
-                --no-build \
-                ${dotnetInstallFlags[@]}  \
-                ${dotnetFlags[@]}
-    done
+    dotnetPublish() {
+        local -r project="${1-}"
+        env dotnet publish ${project-} \
+            -p:ContinuousIntegrationBuild=true \
+            -p:Deterministic=true \
+            -p:UseAppHost=true \
+            --output "$out/lib/${pname}" \
+            --configuration "@buildType@" \
+            --no-build \
+            ${dotnetInstallFlags[@]}  \
+            ${dotnetFlags[@]}
+    }
 
-    if [[ "${packNupkg-}" ]]; then
+    dotnetPack() {
+        local -r project="${1-}"
+         env dotnet pack ${project-} \
+             -p:ContinuousIntegrationBuild=true \
+             -p:Deterministic=true \
+             --output "$out/share" \
+             --configuration "@buildType@" \
+             --no-build \
+             ${dotnetPackFlags[@]}  \
+             ${dotnetFlags[@]}
+    }
+
+    if (( "${#projectFile[@]}" == 0 )); then
+        dotnetPublish
+    else
         for project in ${projectFile[@]}; do
-            env \
-                dotnet pack "$project" \
-                    -p:ContinuousIntegrationBuild=true \
-                    -p:Deterministic=true \
-                    --output "$out/share" \
-                    --configuration "@buildType@" \
-                    --no-build \
-                    ${dotnetPackFlags[@]}  \
-                    ${dotnetFlags[@]}
+            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"