Search code examples
c#visual-studio-2015vsix

How to Bootstrap an VSIX VS2015 Extension


My extension only gets called if I click on a button. Only than the ctor CommandHandlerPackage is called and the CommandMenu items are registered.

But I want to DefaultDisable the Buttons and only enable them if I open the right Solution. To do that I need to register some Events from IVsSolutionEvents but I cant do this from the begining because the extension is initialized only if I interact with it.

So my question is is there something like a bootstrap for this scenario?


Solution

  • You can add the ProvideAutoLoad attribute to your Package class like so:

    [ProvideAutoLoad(UIContextGuids80.SolutionExists)]
    public sealed class VSPackage : Package
    {
      ...
    }
    

    This will automatically run the Initialize method of your package class when a file or project is open.