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

ExtensionConfiguration.LoadedWhen: Extension is active for projects that do not meet defined ActivationConstraint.ActiveProjectCapability #427

Open
i-m-luke opened this issue Oct 4, 2024 · 0 comments

Comments

@i-m-luke
Copy link

i-m-luke commented Oct 4, 2024

My goal is to create an extension that will be active only for projects with specific ProjectCapabilities (e.g., ProjectCapability.JavaScript).

I've implemented this configuration in the extension entrypoint class:

internal class ExtensionEntrypoint : Extension
{
    public override ExtensionConfiguration ExtensionConfiguration => new()
    {
        RequiresInProcessHosting = true,
        LoadedWhen = ActivationConstraint.ActiveProjectCapability(ProjectCapability.JavaScript)
    };
}

But when I select a project that has no "JavaScript" capability, the extension is still active (I can access its commands, etc.).

For checking the project capabilities, I use the VS.Extensibility API. I simply query the solution for its projects and then inspect the project capabilities listed in the Capabilities property. Here is the code:

var projects = await context.Extensibility
    .Workspaces()
    .QuerySolutionAsync(
        query => query.Get(solution => solution.Projects)
            .With(p => p.Name)
            .With(p => p.TypeGuid)
            .With(p => p.Capabilities)
            .With(p => p.Guid)
            .With(p => p.Kind)
            .With(p => p.Type),
        cancellationToken);
// there is only one project in the solution so I'm indexing 0
var capabilities = projects[0].Capabilities

The capabilities variable contains a list with the CSharp capability (and more), but no capability for JavaScript (which is right, because the project is CSharp).

So my issue is that even though the project is CSharp and not JavaScript, the extension is available to use, which is not what I need.


UPDATE:
I've just noticed that even though I run a completely different extension from a completely different project, the commands are still available, so maybe the problem is that there is something old in the cache. However, the current dll (the one with the extension configuration) is loaded because the breakpoints in this project are hit, so maybe my issue is actually not related to this observation.

@i-m-luke i-m-luke changed the title ExtensionConfiguration.LoadedWhen: Extension is active for projects that doesn't meet defined ActivationConstraint.ActiveProjectCapability ExtensionConfiguration.LoadedWhen: Extension is active for projects that don't meet defined ActivationConstraint.ActiveProjectCapability Oct 4, 2024
@i-m-luke i-m-luke changed the title ExtensionConfiguration.LoadedWhen: Extension is active for projects that don't meet defined ActivationConstraint.ActiveProjectCapability ExtensionConfiguration.LoadedWhen: Extension is active for projects that do not meet defined ActivationConstraint.ActiveProjectCapability Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant