3 , buildPackages # buildDotnetModule, dotnet-runtime
9 inherit (buildPackages) buildDotnetModule dotnet-runtime;
11 app = buildDotnetModule {
12 name = "use-dotnet-from-env-test-application";
14 nugetDeps = ./nuget-deps.nix;
15 useDotnetFromEnv = true;
16 env.TargetFramework = "net${lib.versions.majorMinor (lib.getVersion dotnet-sdk)}";
19 appWithoutFallback = app.overrideAttrs (oldAttrs: {
20 nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [
23 postFixup = (oldAttrs.postFixup or "") + ''
24 remove-references-to -t ${dotnet-runtime} "$out/bin/Application"
28 runtimeVersion = lib.getVersion dotnet-runtime;
29 runtimeVersionFile = builtins.toFile "dotnet-version.txt" runtimeVersion;
32 fallback = testers.testEqualContents {
33 assertion = "buildDotnetModule sets fallback DOTNET_ROOT in wrapper";
34 expected = runtimeVersionFile;
35 actual = runCommand "use-dotnet-from-env-fallback-test" { } ''
36 ${app}/bin/Application >"$out"
40 # Check that appWithoutFallback does not use fallback .NET runtime.
41 without-fallback = testers.testBuildFailure (runCommand "use-dotnet-from-env-without-fallback-test" { } ''
42 ${appWithoutFallback}/bin/Application >"$out"
45 # NB assumes that without-fallback above to passes.
46 use-dotnet-root-env = testers.testEqualContents {
47 assertion = "buildDotnetModule uses DOTNET_ROOT from environment in wrapper";
48 expected = runtimeVersionFile;
49 actual = runCommand "use-dotnet-from-env-root-test" { env.DOTNET_ROOT = dotnet-runtime; } ''
50 ${appWithoutFallback}/bin/Application >"$out"
53 use-dotnet-path-env = testers.testEqualContents {
54 assertion = "buildDotnetModule uses DOTNET_ROOT from dotnet in PATH in wrapper";
55 expected = runtimeVersionFile;
56 actual = runCommand "use-dotnet-from-env-path-test" { dotnetRuntime = dotnet-runtime; } ''
57 PATH=$dotnetRuntime''${PATH+:}$PATH ${appWithoutFallback}/bin/Application >"$out"