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

Update dotnet from path resolver to handle a couple more edge cases #6152

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/lsptoolshost/dotnetRuntimeExtensionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CSharpExtensionId } from '../constants/csharpExtensionId';
import { promisify } from 'util';
import { exec } from 'child_process';
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
import { readFile } from 'fs/promises';
import { readFile, readlink } from 'fs/promises';

export const DotNetRuntimeVersion = '7.0';

Expand Down Expand Up @@ -163,13 +163,23 @@ export class DotnetRuntimeExtensionResolver implements IHostExecutableResolver {
throw new Error(`Unable to find dotnet from ${command}.`);
}

const path = whereOutput.stdout.trim();
// There could be multiple paths output from where. Take the first since that is what we used to run dotnet --info.
const path = whereOutput.stdout.trim().replace(/\r/gm, '').split('\n')[0];
if (!existsSync(path)) {
throw new Error(`dotnet path does not exist: ${path}`);
}

this.channel.appendLine(`Using dotnet configured on PATH`);
return path;

// If dotnet is just a symlink, resolve it to the actual executable so
// callers will be able to get the actual directory containing the exe.
try {
const targetPath = await readlink(path);
return targetPath;
} catch {
// Not a symlink.
return path;
}
} catch (e) {
this.channel.appendLine(
'Failed to find dotnet info from path, falling back to acquire runtime via ms-dotnettools.vscode-dotnet-runtime'
Expand Down