Skip to content

Commit 97a83fb

Browse files
committed
Actually acquire .net if does not exist
1 parent f36d8bf commit 97a83fb

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/lsptoolshost/dotnetRuntimeExtensionResolver.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ export class DotnetRuntimeExtensionResolver implements IHostExecutableResolver {
4949
},
5050
versionSpecRequirement: 'greater_than_or_equal',
5151
};
52-
const result = await vscode.commands.executeCommand<IDotnetAcquireResult | undefined>(
52+
let acquireResult = await vscode.commands.executeCommand<IDotnetAcquireResult | undefined>(
5353
'dotnet.findPath',
5454
findPathRequest
5555
);
56-
if (result === undefined) {
57-
throw new Error('Failed to locate .NET runtime');
56+
if (acquireResult === undefined) {
57+
acquireResult = await this.acquireRuntime();
5858
}
5959

60-
dotnetExecutablePath = result.dotnetPath;
60+
dotnetExecutablePath = acquireResult.dotnetPath;
6161
}
6262

6363
const hostInfo = {
@@ -92,6 +92,30 @@ export class DotnetRuntimeExtensionResolver implements IHostExecutableResolver {
9292
return env;
9393
}
9494

95+
/**
96+
* Acquires the .NET runtime if it is not already present.
97+
* @returns The path to the .NET runtime
98+
*/
99+
private async acquireRuntime(): Promise<IDotnetAcquireResult> {
100+
let status = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquireStatus', {
101+
version: DotNetRuntimeVersion,
102+
requestingExtensionId: CSharpExtensionId,
103+
});
104+
if (status === undefined) {
105+
await vscode.commands.executeCommand('dotnet.showAcquisitionLog');
106+
107+
status = await vscode.commands.executeCommand<IDotnetAcquireResult>('dotnet.acquire', {
108+
version: DotNetRuntimeVersion,
109+
requestingExtensionId: CSharpExtensionId,
110+
});
111+
if (!status) {
112+
throw new Error('Could not resolve the dotnet path!');
113+
}
114+
}
115+
116+
return status;
117+
}
118+
95119
private async getArchitectureFromTargetPlatform(): Promise<string | undefined> {
96120
const vsixManifestFile = path.join(this.extensionPath, '.vsixmanifest');
97121
if (!existsSync(vsixManifestFile)) {

0 commit comments

Comments
 (0)