0

I'm working on a VS extension that consist of a toolbar, a toolwindow and a settings page. The whole extension more or less works, but only after loading a solution. As the toolbar contains short-cuts to external applications, it would be favourable to be able to launch those applications already before loading the solution. The main package I set-up as follows:

    [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
    [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
    [ProvideMenuResource("Menus.ctmenu", 1)]
    [ProvideToolWindow(typeof(MyBarToolWindow))]
    [ProvideOptionPage(typeof(UserSettingsPage), "My Toolbar", "Settings", 0, 0, true)]
    [ProvideProfileAttribute(typeof(UserSettingsPage), "MyBar (new)", "General", 1002, 1003, true)]
    [Guid(GroupsGuids.guidMyBarUIPkgString)]
    [ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
    public sealed class MyBar_UIPackage : AsyncPackage, IDteServiceProvider
    {
        private IMyBarSettings settings;

        // .....

        /// <summary>
        /// Called when the VSPackage is loaded by Visual Studio.
        /// </summary>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
        {
            // Switches to the UI thread in order to consume some services used in command initialization
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await base.InitializeAsync(cancellationToken, progress);
            this.GetDte().Events.DTEEvents.OnStartupComplete += this.OnStartupCompleted;
            this.GetDte().Events.SolutionEvents.Opened += this.OnInitialize;
            this.GetDte().Events.WindowEvents.WindowActivated += this.OnWindowEventsWindowActivated;

            // Query service asynchronously from the UI thread
            var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
        }
    }

Somehow Opened WindowActivated and OnStartupComplete don't fire during startup of Visual Studio, but only while loading a solution. Why is that and how can I force the extension to be started with VS?

EDIT: just found out, if I close VS with the toolwindow open, it gets reopened upon next start-up and with that, the extension starts as well. If VS starts up without the toolwindow open, I can't even open the toolwindow because the extension is not yet started-up (hence: loading a solution is necessary).

Robin Holenweger
  • 321
  • 3
  • 14

1 Answers1

1

You can't force the extension to be started with VS. VS 2019+ loads all extensions in background in undetermined time.

But I do recommend to add:

[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66
  • Unfortunately doesn't do the trick, even after adding other decorators as suggested here: https://stackoverflow.com/questions/27687954/visual-studio-extensibility-provideautoload-for-package-cs-for-every-ui-context; but what does "loading in the background" mean in terms of time? Indefinite? – Robin Holenweger Mar 29 '23 at 11:27
  • 1
    @RobinHolenweger In practice, with no or small solution, it takes 10 - 30 seconds to load all ProvideAutoLoad extensions on my machine. – Sergey Vlasov Mar 30 '23 at 05:04