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 4fba131
Show file tree
Hide file tree
Showing 2 changed files with 34 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
34 changes: 34 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,34 @@ 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) {
return;
}

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

try {
// Get path to dotnet cli
const request = { version: '5.0', requestingExtensionId: 'ms-dotnettools.csharp' };
const statusResult = await vscode.commands.executeCommand<{ dotnetPath: string }>('dotnet-sdk.acquireStatus', request);

const success = statusResult.dotnetPath?.length > 0;
if (success) {
const dotnetDirectory = path.dirname(statusResult.dotnetPath);

// Determine if dotnet path should be added to the Environment Path.
if (!process.env.PATH.includes(dotnetDirectory)) {
const appendDotnetPath = path.delimiter + dotnetDirectory;

// Update so that processes started by this extension can invoke `dotnet`
process.env.PATH += appendDotnetPath;
}
}
}
finally {
}
}

0 comments on commit 4fba131

Please sign in to comment.