Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path to dotnet so child processes can use the CLI #4459

Merged
merged 5 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use the dotnet bundle api to get dotnet path
  • Loading branch information
JoeRobich committed Apr 6, 2021
commit 46044446ca46f7c4c808725ccf79bda94f809f0d
24 changes: 24 additions & 0 deletions src/DotnetPack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from "vscode";

const dotnetPackExtensionId = "ms-dotnettools.vscode-dotnet-pack";

export interface DotnetPackExtensionExports {
getDotnetPath(version?: string): Promise<string | undefined>;
}

export async function getDotnetPackApi(): Promise<DotnetPackExtensionExports> {
const dotnetExtension = vscode.extensions.getExtension<DotnetPackExtensionExports>(dotnetPackExtensionId);
if (!dotnetExtension) {
return null;
}

if (!dotnetExtension.isActive) {
await dotnetExtension.activate();
}

return dotnetExtension.exports;
}
28 changes: 8 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { installRuntimeDependencies } from './InstallRuntimeDependencies';
import { isValidDownload } from './packageManager/isValidDownload';
import { BackgroundWorkStatusBarObserver } from './observers/BackgroundWorkStatusBarObserver';
import { getDecompilationAuthorization } from './omnisharp/decompilationPrompt';
import { getDotnetPackApi } from './DotNetPack';

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

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

await tryAddDotNetToPath();
// If the dotnet bundle is installed, this will ensure the dotnet CLI is on the path.
await initializeDotnetPath();

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

async function tryAddDotNetToPath() {
const sdkExtension = vscode.extensions.getExtension("ms-dotnettools.vscode-dotnet-pack");
if (sdkExtension) {
try {
if (!sdkExtension.isActive) {
await sdkExtension.activate();
}

// Invoking acquireStatus updates the process.env.PATH with the folder that contains the dotnet cli.
// This will allow child processes such as OmniSharp to use the dotnet cli.
const request = { version: '5.0', requestingExtensionId: 'ms-dotnettools.csharp' };
const statusResult = await vscode.commands.executeCommand<{ dotnetPath: string }>('dotnet-sdk.acquireStatus', request);

return statusResult.dotnetPath?.length > 0;
}
catch {
}
async function initializeDotnetPath() {
const dotnetPackApi = await getDotnetPackApi();
if (!dotnetPackApi) {
return null;
}

return false;
return await dotnetPackApi.getDotnetPath();
}