Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions vscode-dotnet-runtime-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,17 @@ export function activate(vsCodeContext: vscode.ExtensionContext, extensionContex
const validator = new DotnetConditionValidator(workerContext, utilContext);
const finder = new DotnetPathFinder(workerContext, utilContext);

const dotnetOnShellSpawn = (await finder.findDotnetFastFromListOnly())?.[0] ?? '';
if (dotnetOnShellSpawn)
{
const validatedShellSpawn = await getPathIfValid(dotnetOnShellSpawn, validator, commandContext);
if (validatedShellSpawn)
{
loggingObserver.dispose();
return { dotnetPath: validatedShellSpawn };
}
}

const dotnetsOnPATH = await finder.findRawPathEnvironmentSetting();
for (const dotnetPath of dotnetsOnPATH ?? [])
{
Expand Down
17 changes: 17 additions & 0 deletions vscode-dotnet-runtime-library/src/Acquisition/DotnetPathFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ export class DotnetPathFinder implements IDotnetPathFinder
return undefined;
}

/**
* @remarks This only checks dotnet --list-runtimes or --list-sdks, so it can be more performant for the base case.
* This allows skipping which, where, and also does not rely on --info which is slower because it shells to the SDK instead of just being the host.
* @returns The path to the dotnet executable, which may be a symlink to the actual executable.
*/
public async findDotnetFastFromListOnly(): Promise<string[] | undefined>
{
const oldLookup = process.env.DOTNET_MULTILEVEL_LOOKUP;
try {
process.env.DOTNET_MULTILEVEL_LOOKUP = '0'; // make it so --list-runtimes only finds the runtimes on that path: https://learn.microsoft.com/en-us/dotnet/core/compatibility/deployment/7.0/multilevel-lookup#reason-for-change
Copy link
Member Author

@nagilson nagilson Apr 14, 2025

Choose a reason for hiding this comment

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

Not enabling this will prevent discovery of dotnet subdirectories:

When running the application through [dotnet](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet), subdirectories relative to the dotnet executable.

https://learn.microsoft.com/en-us/dotnet/core/compatibility/deployment/7.0/multilevel-lookup

const finalPath = await this.getTruePath(['dotnet']);
return this.returnWithRestoringEnvironment(finalPath, 'DOTNET_MULTILEVEL_LOOKUP', oldLookup);
} finally {
process.env.DOTNET_MULTILEVEL_LOOKUP = oldLookup; // Ensure the environment variable is always restored
}
}

/**
*
* @returns A set of the path environment variable(s) for which or where dotnet, which may need to be converted to the actual path if it points to a polymorphic executable.
Expand Down
Loading