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 Apr 6, 2021
1 parent 21fd01b commit b1c5e2c
Show file tree
Hide file tree
Showing 2 changed files with 23 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
23 changes: 23 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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 +229,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 b1c5e2c

Please sign in to comment.