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

Fix dotnet path resolution when using snap installed packages #6515

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

dibarbet
Copy link
Member

@dibarbet dibarbet commented Oct 10, 2023

On systems installing dotnet via snap, the dotnet on the path does not point to the dotnet install location, even via symlinks. Instead, it is symlinked to the snap executable, e.g. /usr/bin/snap.

So calling which dotnet and reading symlinks will not give us a valid dotnet installation.

The fix here is to instead parse the output of dotnet --list-runtimes which will return the real assembly locations of the dotnet install. Since the dotnet install has a known layout, we can easily find the dotnet executable given a runtime install path.

See #6513 for more info.

Resolves #6513

@dibarbet dibarbet requested a review from a team as a code owner October 10, 2023 22:11
if (!existsSync(dotnetExecutablePath)) {
throw new Error(
`dotnet executable path does not exist: ${dotnetExecutablePath}, dotnet installation may be corrupt.`
);
}

this.channel.appendLine(`Using dotnet configured on PATH`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this message need to change? Or should it now log the path we created?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the path will be logged in the caller anway, and we're still using the dotnet from the path, so think this is fine.

Comment on lines +171 to +172
// Therefore we know that the runtime path is always in <install root>/shared/<runtime name>
// and the dotnet executable is always at <install root>/dotnet(.exe).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be renaming this function? (findDotnetFromPath)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still valid - this is still from the dotnet on path (via executing the dotnet commands)

@zaballa12
Copy link

zaballa12 commented Oct 11, 2023

So what do I have to do to fix this problem?

dotnet --list-runtimes
Microsoft.AspNetCore.App 7.0.11 [/snap/dotnet-sdk/221/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.11 [/snap/dotnet-sdk/221/shared/Microsoft.NETCore.App]

@dibarbet
Copy link
Member Author

So what do I have to do to fix this problem?

dotnet --list-runtimes Microsoft.AspNetCore.App 7.0.11 [/snap/dotnet-sdk/221/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 7.0.11 [/snap/dotnet-sdk/221/shared/Microsoft.NETCore.App]

This change will most likely be in next weeks release which should resolve the issue. If you want to workaround it for now, I think there are a few options.

If you're only using C# (and not C# devkit), you can workaround this issue by setting dotnet.dotnetPath to /snap/dotnet-sdk/221/ in your vscode configuration.

Alternatively, making sure the dotnet executable at /snap/dotnet-sdk/221/dotnet is in your path before /snap/bin/dotnet should also resolve this.

Another user also mentioned running this - ln -s /snap/bin/dotnet /usr/bin/dotnet worked, though I haven't tried it.

@dibarbet dibarbet merged commit 448fdda into dotnet:main Oct 11, 2023
8 checks passed
@dibarbet dibarbet deleted the fix_dotnet_path_snap branch October 11, 2023 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There are some problems connecting to the language server
3 participants