Skip to content

Commit af19ffa

Browse files
authored
Merge pull request #6152 from dibarbet/update_dotnet_path
Update dotnet from path resolver to handle a couple more edge cases
2 parents 9e3b0fa + 73829b0 commit af19ffa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lsptoolshost/dotnetRuntimeExtensionResolver.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { CSharpExtensionId } from '../constants/csharpExtensionId';
1515
import { promisify } from 'util';
1616
import { exec } from 'child_process';
1717
import { getDotnetInfo } from '../shared/utils/getDotnetInfo';
18-
import { readFile } from 'fs/promises';
18+
import { readFile, readlink } from 'fs/promises';
1919

2020
export const DotNetRuntimeVersion = '7.0';
2121

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

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

171172
this.channel.appendLine(`Using dotnet configured on PATH`);
172-
return path;
173+
174+
// If dotnet is just a symlink, resolve it to the actual executable so
175+
// callers will be able to get the actual directory containing the exe.
176+
try {
177+
const targetPath = await readlink(path);
178+
return targetPath;
179+
} catch {
180+
// Not a symlink.
181+
return path;
182+
}
173183
} catch (e) {
174184
this.channel.appendLine(
175185
'Failed to find dotnet info from path, falling back to acquire runtime via ms-dotnettools.vscode-dotnet-runtime'

0 commit comments

Comments
 (0)