Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong DOTNET_ROOT inferring on OSTree-style .NET installations #6239

Closed
GGG-KILLER opened this issue Aug 28, 2023 · 8 comments
Closed

Wrong DOTNET_ROOT inferring on OSTree-style .NET installations #6239

GGG-KILLER opened this issue Aug 28, 2023 · 8 comments

Comments

@GGG-KILLER
Copy link

Environment data

VSCode version: 1.81.1
C# Extension: 2.0.413
Using OmniSharp: false

Dotnet Information .NET SDK: Version: 8.0.100-preview.5.23303.2 Commit: 3fe444af72

Runtime Environment:
OS Name: nixos
OS Version: 23.11
OS Platform: Linux
RID: linux-x64
Base Path: /nix/store/4bj5f8yjjim8wryazs31ix0npcwilpwp-dotnet-sdk-8.0.100-preview.5.23303.2/sdk/8.0.100-preview.5.23303.2/

.NET workloads installed:
There are no installed workloads to display.

Host:
Version: 8.0.0-preview.5.23280.8
Architecture: x64
Commit: bc78804f5d

.NET SDKs installed:
6.0.412 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/sdk]
7.0.306 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/sdk]
8.0.100-preview.5.23303.2 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.20 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.9 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-preview.5.23302.2 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.20 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.9 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-preview.5.23280.8 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Steps to reproduce

  1. Install a Linux distro where .NET is installed in OSTree style (e.g. NixOS)
  2. Install the extension (and patch the binaries if you're on NixOS)
  3. Configure the extension to use the installed .NET
  4. Open a .NET project
  5. Have the extension fail with ".NET is not installed"

Expected behavior

Extension detects that the dotnet binary is in the bin dir and goes up another directory to get DOTNET_ROOT.

Actual behavior

Binary fails to launch with "Install .NET to run this binary" because of the wrong DOTNET_ROOT location.

Additional context

I have implemented a fix in the build script for my system however it'd be best if this were solved upstream.

@dibarbet
Copy link
Member

If a .net7 SDK is available on your path, we should be able to use it. We look for the location of that dotnet on path and set the DOTNET_ROOT to its parent dir.

Can you share the C# output window logs? Preferably with the dotnet.server.trace setting set to Trace

@dibarbet dibarbet added this to the September milestone Aug 30, 2023
@GGG-KILLER
Copy link
Author

GGG-KILLER commented Aug 31, 2023

The issue is that the fetching for the DOTNET_ROOT is incorrect for OSTree-style installations, in NixOS' case, the path for dotnet is:
/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/bin/dotnet
which after dirname is:
/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/bin
however, the correct location would be (another directory up):
/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined

I'll fetch the C# output window logs shortly

@GGG-KILLER
Copy link
Author

GGG-KILLER commented Aug 31, 2023

@dibarbet here's the C# output window logs with dotnet.server.trace set to Trace: https://gist.github.com/GGG-KILLER/54e26c1271a4bf5085b790252b8b9c45

As well as the dotnet --info output:

dotnet --info output
.NET SDK:
 Version:   8.0.100-preview.5.23303.2
 Commit:    3fe444af72

Runtime Environment:
 OS Name:     nixos
 OS Version:  23.11
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/4bj5f8yjjim8wryazs31ix0npcwilpwp-dotnet-sdk-8.0.100-preview.5.23303.2/sdk/8.0.100-preview.5.23303.2/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-preview.5.23280.8
  Architecture: x64
  Commit:       bc78804f5d

.NET SDKs installed:
  6.0.412 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/sdk]
  7.0.306 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/sdk]
  8.0.100-preview.5.23303.2 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.20 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.9 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-preview.5.23302.2 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.20 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.9 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-preview.5.23280.8 [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined]

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Something that might be useful, is that /nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/bin/dotnet (at least currenty, that might change in the future) is a link to /nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/dotnet, so maybe following links more aggressively might be a temporary solution?

UPDATE: it seems that following links further has been done in #6230, so after updating to 2.0.436 the double dirname is no longer needed.

@dibarbet
Copy link
Member

Something that might be useful, is that /nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/bin/dotnet (at least currenty, that might change in the future) is a link to /nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined/dotnet, so maybe following links more aggressively might be a temporary solution?

UPDATE: it seems that following links further has been done in #6230, so after updating to 2.0.436 the double dirname is no longer needed.

Yup as you mention we should now be looking at where the dotnet executable is symlinked to, and finding that folder. That seems to be a fairly common pattern on linux systems, so we'll continue to support that scenario. Does that solution work then?

Note - while there are potentially more cases we can consider here for dotnet resolution, unless they're extremely motivating we're not going to be able to handle them all automatically. There's just so many different possible configurations of dotnet installations out there that it's basically chasing an infinite rabbit hole. For those real edge cases, we expect a combination of

  1. the fallback to downloading the runtime via the .NET runtime acquisition extension (if no other applicable dotnet is found) OR
  2. the dotnet path vscode configuration settings (dotnet.dotnetPath and/or dotnetAcquisitionExtension.existingDotnetPath)

to cover the rest.

@GGG-KILLER
Copy link
Author

GGG-KILLER commented Aug 31, 2023

Yup as you mention we should now be looking at where the dotnet executable is symlinked to, and finding that folder. That seems to be a fairly common pattern on linux systems, so we'll continue to support that scenario. Does that solution work then?

Yes it does indeed work, I was able to remove the workaround I had implemented for it

  1. the fallback to downloading the runtime via the .NET runtime acquisition extension (if no other applicable dotnet is found)

This is not really an option in NixOS as libc, icu and even the ELF interpreter are not in standard locations, so all binaries need to be patched to work on it, maybe a setting to specify DOTNET_ROOT (or using the one from the process env instead of trying to find it again) would be a fix-all solution (in case the one in /bin is not a symlink)?

  1. the dotnet path vscode configuration settings (dotnet.dotnetPath and/or dotnetAcquisitionExtension.existingDotnetPath)

This also doesn't work because if the actual path were inside a /bin dir (which is a common thing on OSTree style systems), it'd use dirname to get the DOTNET_ROOT and then wrongly assume the /bin dir was the DOTNET_ROOT, when it actually is the parent directory of /bin.

@dibarbet
Copy link
Member

This also doesn't work because if the actual path were inside a /bin dir (which is a common thing on OSTree style systems), it'd use dirname to get the DOTNET_ROOT and then wrongly assume the /bin dir was the DOTNET_ROOT, when it actually is the parent directory of /bin.

In this case, the dotnet.dotnetPath is supposed to point to the folder, not the executable. So you would set the value to /nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined and not the bin directory.

@GGG-KILLER
Copy link
Author

In this case, the dotnet.dotnetPath is supposed to point to the folder, not the executable. So you would set the value to /nix/store/5ddzdgh38p44zf5ijqfdxzndijzgw5wd-dotnet-core-combined and not the bin directory.

Oh, I see, fair enough then, my bad

@dibarbet
Copy link
Member

dibarbet commented Sep 6, 2023

Going to close this as I think the original problem is fixed and we're not planning on taking additional action here

@dibarbet dibarbet closed this as completed Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants