Dotnet --list-sdks (Multiple .NET Versions)

I’ve installed both version 6 and 7


, but I only see one of them:

dotnet --list-sdks
6.0.408 [/nix/store/yzbqvjy3j89fzh8v5dn2hzkvvv0x23xx-dotnet-sdk-6.0.408/sdk]

My environment is:

      DOTNET_ROOT = "${pkgs.dotnet-sdk}";

Any pointers as to how I can let it know about the second one?:wink:

How did you install them?

Is that part of your system environment? Or a Dev shell?

Unless it’s the latter you should move to the latter.

1 Like

They are systemPackages:

  environment.systemPackages = with pkgs; [

I have to move it to devshell, as in this?:

You do not necessarily need a library to create a dev shell.

It is just a term, that I (and some other people) use interchangeably with “nix shell”, as the relevant flake output now is named “devShells”.

ok, but a flake still needs to write an environment variable to have it see multiple versions of .NET, right, so how would that be done differently?

You don’t use both at the same time, you selectively load only the relevant shell.

Also flakes are not relevant for this.

To use multiple .net versions, use dotnetCorePackages.combinePackages.

I’m still on 22.05 and I get this:

quasar in ~/.pkg/test-shell
BASHY $ nix-shell testshell.nix
error: undefined variable 'sdk_7_0'

       at /mnt/7440b882-aecb-4e4a-8ecb-24d7a31dc9f9/home/b0ef/.pkg/test-shell/testshell.nix:8:7:

            7|       sdk_6_0
            8|       sdk_7_0
             |       ^
            9|     ])
(use '--show-trace' to show detailed location information)

You really want to update, 22.05 is EOL since last November.

Still, I checked for you, and sdk_7_0 isn’t available in 22.05. You need to get it from 22.11 or newer.

Though then you should get the full dotnetCorePackages from there.

And my initial concern about using combined packages over individual isolated shells or derivations remains.

$ nix repl -f '<nixpkgs>' -I nixpkgs=channel:nixos-22.05
Welcome to Nix 2.16.0pre20230502_1540ab7. Type :? for help.

Loading installable ''...
Added 16551 variables.
nix-repl> dotnetCorePackages.sdk_<TAB>
dotnetCorePackages.sdk_2_1  dotnetCorePackages.sdk_2_2  dotnetCorePackages.sdk_3_0  dotnetCorePackages.sdk_3_1  dotnetCorePackages.sdk_5_0  dotnetCorePackages.sdk_6_0

I install it via unstable, (unstable.dotnet-sdk_7)

BASHY $ dotnet --list-sdks
7.0.203 [/nix/store/yqbh0x0zk7jn1m9pxhi61qrhyf2i08n1-dotnet-sdk-7.0.203/sdk]