buildDotnetModule: support setting projectFile as an array && properly interpret disabledTests

Changed files
+46 -38
doc
languages-frameworks
pkgs
build-support
build-dotnet-module
+1 -1
doc/languages-frameworks/dotnet.section.md
···
To package Dotnet applications, you can use `buildDotnetModule`. This has similar arguments to `stdenv.mkDerivation`, with the following additions:
-
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions.
+
* `projectFile` has to be used for specifying the dotnet project file relative to the source root. These usually have `.sln` or `.csproj` file extensions. This can be an array of multiple projects as well.
* `nugetDeps` has to be used to specify the NuGet dependency file. Unfortunately, these cannot be deterministically fetched without a lockfile. This file should be generated using `nuget-to-nix` tool, which is available in nixpkgs.
* `executables` is used to specify which executables get wrapped to `$out/bin`, relative to `$out/lib/$pname`. If this is unset, all executables generated will get installed. If you do not want to install any, set this to `[]`.
* `runtimeDeps` is used to wrap libraries into `LD_LIBRARY_PATH`. This is how dotnet usually handles runtime dependencies.
+45 -37
pkgs/build-support/build-dotnet-module/default.nix
···
# 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
-
# The packages project file, which contains instructions on how to compile it.
+
# 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 using the `nuget-to-nix` tool.
···
export HOME=$(mktemp -d)
-
dotnet restore "$projectFile" \
-
${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
-
-p:ContinuousIntegrationBuild=true \
-
-p:Deterministic=true \
-
--source "${nuget-source}/lib" \
-
"''${dotnetRestoreFlags[@]}" \
-
"''${dotnetFlags[@]}"
+
for project in ''${projectFile[@]}; do
+
dotnet restore "$project" \
+
${lib.optionalString (!enableParallelBuilding) "--disable-parallel"} \
+
-p:ContinuousIntegrationBuild=true \
+
-p:Deterministic=true \
+
--source "${nuget-source}/lib" \
+
"''${dotnetRestoreFlags[@]}" \
+
"''${dotnetFlags[@]}"
+
done
runHook postConfigure
'';
···
buildPhase = args.buildPhase or ''
runHook preBuild
-
dotnet build "$projectFile" \
-
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
-
-p:BuildInParallel=${if enableParallelBuilding then "true" else "false"} \
-
-p:ContinuousIntegrationBuild=true \
-
-p:Deterministic=true \
-
-p:Version=${args.version} \
-
--configuration "$buildType" \
-
--no-restore \
-
"''${dotnetBuildFlags[@]}" \
-
"''${dotnetFlags[@]}"
+
for project in ''${projectFile[@]}; do
+
dotnet build "$project" \
+
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
+
-p:BuildInParallel=${if enableParallelBuilding then "true" else "false"} \
+
-p:ContinuousIntegrationBuild=true \
+
-p:Deterministic=true \
+
-p:Version=${args.version} \
+
--configuration "$buildType" \
+
--no-restore \
+
"''${dotnetBuildFlags[@]}" \
+
"''${dotnetFlags[@]}"
+
done
runHook postBuild
'';
···
checkPhase = args.checkPhase or ''
runHook preCheck
-
${lib.getBin dotnet-test-sdk}/bin/dotnet test "$testProjectFile" \
-
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
-
-p:ContinuousIntegrationBuild=true \
-
-p:Deterministic=true \
-
--configuration "$buildType" \
-
--no-build \
-
--logger "console;verbosity=normal" \
-
${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "|FullyQualifiedName!=" disabledTests}\""} \
-
"''${dotnetTestFlags[@]}" \
-
"''${dotnetFlags[@]}"
+
for project in ''${testProjectFile[@]}; do
+
${lib.getBin dotnet-test-sdk}/bin/dotnet test "$project" \
+
-maxcpucount:${if enableParallelBuilding then "$NIX_BUILD_CORES" else "1"} \
+
-p:ContinuousIntegrationBuild=true \
+
-p:Deterministic=true \
+
--configuration "$buildType" \
+
--no-build \
+
--logger "console;verbosity=normal" \
+
${lib.optionalString (disabledTests != []) "--filter \"FullyQualifiedName!=${lib.concatStringsSep "&FullyQualifiedName!=" disabledTests}\""} \
+
"''${dotnetTestFlags[@]}" \
+
"''${dotnetFlags[@]}"
+
done
runHook postCheck
'';
···
installPhase = args.installPhase or ''
runHook preInstall
-
dotnet publish "$projectFile" \
-
-p:ContinuousIntegrationBuild=true \
-
-p:Deterministic=true \
-
--output $out/lib/${args.pname} \
-
--configuration "$buildType" \
-
--no-build \
-
--no-self-contained \
-
"''${dotnetInstallFlags[@]}" \
-
"''${dotnetFlags[@]}"
+
for project in ''${projectFile[@]}; do
+
dotnet publish "$project" \
+
-p:ContinuousIntegrationBuild=true \
+
-p:Deterministic=true \
+
--output $out/lib/${args.pname} \
+
--configuration "$buildType" \
+
--no-build \
+
--no-self-contained \
+
"''${dotnetInstallFlags[@]}" \
+
"''${dotnetFlags[@]}"
+
done
'' + (if executables != null then ''
for executable in $executables; do
execPath="$out/lib/${args.pname}/$executable"