From 73829b0d20783fec00fbd9317e4974e8a69272bf Mon Sep 17 00:00:00 2001 From: David Barbet Date: Wed, 16 Aug 2023 15:49:02 -0700 Subject: [PATCH] Update dotnet from path resolver to handle a couple more edge cases --- .../dotnetRuntimeExtensionResolver.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lsptoolshost/dotnetRuntimeExtensionResolver.ts b/src/lsptoolshost/dotnetRuntimeExtensionResolver.ts index d80919f43..7cdddf71d 100644 --- a/src/lsptoolshost/dotnetRuntimeExtensionResolver.ts +++ b/src/lsptoolshost/dotnetRuntimeExtensionResolver.ts @@ -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'; @@ -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'