Skip to content

Commit 4604444

Browse files
committed
Use the dotnet bundle api to get dotnet path
1 parent aac263e commit 4604444

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/DotnetPack.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
import * as vscode from "vscode";
6+
7+
const dotnetPackExtensionId = "ms-dotnettools.vscode-dotnet-pack";
8+
9+
export interface DotnetPackExtensionExports {
10+
getDotnetPath(version?: string): Promise<string | undefined>;
11+
}
12+
13+
export async function getDotnetPackApi(): Promise<DotnetPackExtensionExports> {
14+
const dotnetExtension = vscode.extensions.getExtension<DotnetPackExtensionExports>(dotnetPackExtensionId);
15+
if (!dotnetExtension) {
16+
return null;
17+
}
18+
19+
if (!dotnetExtension.isActive) {
20+
await dotnetExtension.activate();
21+
}
22+
23+
return dotnetExtension.exports;
24+
}

src/main.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { installRuntimeDependencies } from './InstallRuntimeDependencies';
4545
import { isValidDownload } from './packageManager/isValidDownload';
4646
import { BackgroundWorkStatusBarObserver } from './observers/BackgroundWorkStatusBarObserver';
4747
import { getDecompilationAuthorization } from './omnisharp/decompilationPrompt';
48+
import { getDotnetPackApi } from './DotNetPack';
4849

4950
export async function activate(context: vscode.ExtensionContext): Promise<CSharpExtensionExports> {
5051

@@ -148,7 +149,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
148149
return null;
149150
}
150151

151-
await tryAddDotNetToPath();
152+
// If the dotnet bundle is installed, this will ensure the dotnet CLI is on the path.
153+
await initializeDotnetPath();
152154

153155
let telemetryObserver = new TelemetryObserver(platformInfo, () => reporter);
154156
eventStream.subscribe(telemetryObserver.post);
@@ -229,24 +231,10 @@ async function ensureRuntimeDependencies(extension: vscode.Extension<CSharpExten
229231
return installRuntimeDependencies(extension.packageJSON, extension.extensionPath, installDependencies, eventStream, platformInfo);
230232
}
231233

232-
async function tryAddDotNetToPath() {
233-
const sdkExtension = vscode.extensions.getExtension("ms-dotnettools.vscode-dotnet-pack");
234-
if (sdkExtension) {
235-
try {
236-
if (!sdkExtension.isActive) {
237-
await sdkExtension.activate();
238-
}
239-
240-
// Invoking acquireStatus updates the process.env.PATH with the folder that contains the dotnet cli.
241-
// This will allow child processes such as OmniSharp to use the dotnet cli.
242-
const request = { version: '5.0', requestingExtensionId: 'ms-dotnettools.csharp' };
243-
const statusResult = await vscode.commands.executeCommand<{ dotnetPath: string }>('dotnet-sdk.acquireStatus', request);
244-
245-
return statusResult.dotnetPath?.length > 0;
246-
}
247-
catch {
248-
}
234+
async function initializeDotnetPath() {
235+
const dotnetPackApi = await getDotnetPackApi();
236+
if (!dotnetPackApi) {
237+
return null;
249238
}
250-
251-
return false;
239+
return await dotnetPackApi.getDotnetPath();
252240
}

0 commit comments

Comments
 (0)