Visual Studio Extensibility: ProvideAutoLoad for Package.cs for every UI Context
Asked Answered
D

2

8

My goal is to create a "Visual Studio Extensibility" which adds a "Npm install" Context Menu Item to a package.json file.

So far, this works great if I open a solution, because I've added the [ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.SolutionExists)] attribute to the Package class.

But it's not working if I open a Web Site (File->Open->Web Site...). Do you have any idea, how I can AutoLoad the Package.cs for every UI Context?

Edit: More information after further investigation: If I save the Web Site as a Solution, the "Initialize"-Method is called. But the BeforeQueryStatus of the MenuItem of package.json is not called. The solution structure looks like this:

-Solution
 -project
  -package.json

If I add the package.json directly into the solution, the Context Menu Item appears. Structure:

-Solution
 -Solution Items
  -package.json
 -project

Any ideas?

Dap answered 29/12, 2014 at 11:26 Comment(0)
L
7

Add the below code to your package definition:

[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasSingleProject_string)]

Your package should load in all scenarios.

Like answered 11/4, 2017 at 11:49 Comment(0)
C
1

You can add the second ProvideAutoLoad attribute with the NoSolution value to load your package in all contexts.

Cherenkov answered 30/12, 2014 at 6:11 Comment(1)
It's still not working. I think it's somehow, because the "project" is not a real project, but a web site. Somehow, the parent seems to be another. So far, I add following parent to the button: <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>Dap

© 2022 - 2024 — McMap. All rights reserved.