Skip to content

Commit

Permalink
Add path to dotnet so child processes can use the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Mar 26, 2021
1 parent f7544cb commit 164d13a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}"
],
"stopOnEntry": false,
Expand Down
24 changes: 24 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as OmniSharp from './omnisharp/extension';
import * as coreclrdebug from './coreclr-debug/activate';
import * as util from './common';
import * as vscode from 'vscode';
import * as path from 'path';

import { ActivationFailure, ActiveTextEditorChanged } from './omnisharp/loggingEvents';
import { WarningMessageObserver } from './observers/WarningMessageObserver';
Expand Down Expand Up @@ -148,6 +149,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
return null;
}

await tryAddDotNetToPath();

let telemetryObserver = new TelemetryObserver(platformInfo, () => reporter);
eventStream.subscribe(telemetryObserver.post);

Expand Down Expand Up @@ -227,3 +230,24 @@ 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 {
}
}

return false;
}

0 comments on commit 164d13a

Please sign in to comment.