Gary Ewan Park
Gary Ewan Park

Reputation: 19021

Error when dependent extension is disabled in favour of new preview extension

I have a Visual Studio Code Extension that takes a dependency on the PowerShell extension. This is done here:

https://github.com/gep13/chocolatey-vscode/blob/develop/package.json#L136

It has been pointed out that this causes a problem when a user is using the PowerShell Preview extension. As it causes an error, which I assume is due to the dependency not being met.

My extension doesn't really care whether it is the PowerShell or the PowerShell Preview extension.

Is there a way in my extension manifest to specify that it can be either one, or the other? Or would it be better to review the dependency in favour of a recommendation for the PowerShell Extension?

Upvotes: 2

Views: 83

Answers (1)

Gama11
Gama11

Reputation: 34158

I don't think there's a way to enforce an either/or relationship in the manifest.

As an alternative, you could perhaps make it so that ms-vscode.PowerShell is not a hard requirement by putting it in extensionPack instead. That way, installing your extension would still install it as well, but it can be disabled or even uninstalled.

You could then verify that the dependency is met when your extension is activated:

if (vscode.extensions.getExtension("ms-vscode.PowerShell") === undefined && 
    vscode.extensions.getExtension("ms-vscode.PowerShell-Preview") == undefined) {
    vscode.window.showErrorMessage("PowerShell or PowerShell Preview extension required");
}

Upvotes: 2

Related Questions