diff --git a/pkgs/build-support/dotnet/make-nuget-source/default.nix b/pkgs/build-support/dotnet/make-nuget-source/default.nix index 6bda65f18d5..a23a143ab24 100644 --- a/pkgs/build-support/dotnet/make-nuget-source/default.nix +++ b/pkgs/build-support/dotnet/make-nuget-source/default.nix @@ -15,12 +15,10 @@ let buildCommand = '' mkdir -p $out/{lib,share} - ( - shopt -s nullglob - for nupkg in ${lib.concatMapStringsSep " " (dep: "\"${dep}\"/*.nupkg") deps}; do - cp --no-clobber "$nupkg" $out/lib - done - ) + # use -L to follow symbolic links. When `projectReferences` is used in + # buildDotnetModule, one of the deps will be a symlink farm. + find -L ${lib.concatStringsSep " " deps} -type f -name '*.nupkg' -exec \ + cp --no-clobber '{}' $out/lib ';' # Generates a list of all licenses' spdx ids, if available. # Note that this currently ignores any license provided in plain text (e.g. "LICENSE.txt") diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 9f684dcea72..b6793d25b6e 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -86,6 +86,8 @@ with pkgs; coq = callPackage ./coq {}; + dotnet = recurseIntoAttrs (callPackages ./dotnet { }); + makeHardcodeGsettingsPatch = callPackage ./make-hardcode-gsettings-patch { }; makeWrapper = callPackage ./make-wrapper { }; diff --git a/pkgs/test/dotnet/default.nix b/pkgs/test/dotnet/default.nix new file mode 100644 index 00000000000..7592b09d76e --- /dev/null +++ b/pkgs/test/dotnet/default.nix @@ -0,0 +1,5 @@ +{ callPackage }: + +{ + project-references = callPackage ./project-references { }; +} diff --git a/pkgs/test/dotnet/project-references/application/Application.cs b/pkgs/test/dotnet/project-references/application/Application.cs new file mode 100644 index 00000000000..ae2c956a4df --- /dev/null +++ b/pkgs/test/dotnet/project-references/application/Application.cs @@ -0,0 +1 @@ +ProjectReferencesTest.Library.Hello(); diff --git a/pkgs/test/dotnet/project-references/application/Application.csproj b/pkgs/test/dotnet/project-references/application/Application.csproj new file mode 100644 index 00000000000..6507637a553 --- /dev/null +++ b/pkgs/test/dotnet/project-references/application/Application.csproj @@ -0,0 +1,10 @@ + + + exe + + + + + + + diff --git a/pkgs/test/dotnet/project-references/default.nix b/pkgs/test/dotnet/project-references/default.nix new file mode 100644 index 00000000000..f40b9196c20 --- /dev/null +++ b/pkgs/test/dotnet/project-references/default.nix @@ -0,0 +1,38 @@ +# Tests the `projectReferences = [ ... ];` feature of buildDotnetModule. +# The `library` derivation exposes a .nupkg, which is then consumed by the `application` derivation. +# https://nixos.org/manual/nixpkgs/unstable/index.html#packaging-a-dotnet-application + +{ lib +, dotnet-sdk +, buildDotnetModule +, runCommand +}: + +let + nugetDeps = ./nuget-deps.nix; + + # Specify the TargetFramework via an environment variable so that we don't + # have to update the .csproj files when updating dotnet-sdk + TargetFramework = "net${lib.versions.majorMinor (lib.getVersion dotnet-sdk)}"; + + library = buildDotnetModule { + name = "project-references-test-library"; + src = ./library; + inherit nugetDeps TargetFramework; + + packNupkg = true; + }; + + application = buildDotnetModule { + name = "project-references-test-application"; + src = ./application; + inherit nugetDeps TargetFramework; + + projectReferences = [ library ]; + }; +in + +runCommand "project-references-test" { } '' + ${application}/bin/Application + touch $out +'' diff --git a/pkgs/test/dotnet/project-references/library/Library.cs b/pkgs/test/dotnet/project-references/library/Library.cs new file mode 100644 index 00000000000..a4af4a0fea2 --- /dev/null +++ b/pkgs/test/dotnet/project-references/library/Library.cs @@ -0,0 +1,8 @@ +namespace ProjectReferencesTest; +public static class Library +{ + public static void Hello() + { + System.Console.WriteLine("Hello, World!"); + } +} diff --git a/pkgs/test/dotnet/project-references/library/Library.csproj b/pkgs/test/dotnet/project-references/library/Library.csproj new file mode 100644 index 00000000000..b9a71276d24 --- /dev/null +++ b/pkgs/test/dotnet/project-references/library/Library.csproj @@ -0,0 +1,5 @@ + + + ProjectReferencesTest.Library + + diff --git a/pkgs/test/dotnet/project-references/nuget-deps.nix b/pkgs/test/dotnet/project-references/nuget-deps.nix new file mode 100644 index 00000000000..f3a17967e25 --- /dev/null +++ b/pkgs/test/dotnet/project-references/nuget-deps.nix @@ -0,0 +1,5 @@ +# This file was automatically generated by passthru.fetch-deps. +# Please dont edit it manually, your changes might get overwritten! + +{ fetchNuGet }: [ +]