0

This question deals with my question, just not with changes made in Visual Studio 2019, where VSIX projects load asynchronously, where in previous versions of Visual Studio VSIX projects loaded synchronously.

I am using IVsSolutionEvents3 in my VSIX projects to get notified of

VSTestPackage1: OnAfterOpenProject
VSTestPackage1: OnQueryCloseSolution
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseSolution
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseProject
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseProject
VSTestPackage1: OnAfterCloseSolution

I modified the decoration to my VSIX project to incorporate the recommended SolutionExistsAndFullyLoaded, however the I do not get any notifications for the very first solution that a user opens. In VS2019 that is from there new dialog that shows prior to the actual IDE.

[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string, PackageAutoLoadFlags.BackgroundLoad)]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(VSTestPackage1.PackageGuidString)]
[InstalledProductRegistration("#110", "#112", "2017.1.4.664", IconResourceID = 400)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[ProvideMenuResource("Menus.ctmenu", 1)]
public sealed class VSTestPackage1 :
    AsyncPackage,
    IVsSolutionEvents3,
    IVsUpdateSolutionEvents,
    IVsBuildStatusCallback,
    IDisposable
{
}

I receive notifications for all solutions after the initial solution loads and for the closing of the initial solution, just not the loading of the initial solution. What I see from debugging is that after the initial solution loads, my VSIX projects initializes.

protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
     System.Diagnostics.Debug.WriteLine("VSTestPackage1: Entering Initialize()");
     ...
}

The InitializeAsync() call does not provide a IVsHierarchy pHierarchy, which would allow me to extract the already open solution/project.

How can I get notified of the initial solution/project?

Sarah Weinberger
  • 15,041
  • 25
  • 83
  • 130

2 Answers2

1

Simple answer is you cannot, as your package is now being loaded asynchronously, so the solution may have already been loaded, and fired those events, before your package has the opportunity to sink/advise on those event interfaces. You'll need change up the logic in your package to accommodate this possibility.

Basically, you'll need to see if a solution or project you are interested in is already loaded, and process it accordingly.

Mad's posted a blog describing the impact on the move to async package loading in the following in one of his earlier blog posts:

Improving the responsiveness of critical scenarios by updating auto load behavior for extensions

In particular the section "Impact on package implementations".

Sincerely,

Ed Dore
  • 2,013
  • 1
  • 10
  • 8
0

I found that if you include a ToolWindow in your VSIX and this ToolWindow is in the configuration package.cs like,

[ProvideToolWindow(typeof(ToolWindow1))]

.. and suppose your ToolWindow1 is shown via some Menu View/Other Windows, you have properly sized it and left it on screen when closing Visual Studio. After that, start Visual Studio again and load a solution.. The Toolwindow will show very quickly, and the loading of the ToolWindow will preceed the loading of the first Solution !

On loading its UI, Visual Studio will show the ToolWindow before the solution is loaded, so the constructor of the ToolWindow can set your event handlers. Doing so, you can handle the solution load as usual, through receiving your events and processing them.

I admit this is a trick, not a real solution. When the user chooses to NOT display your ToolWindow, you will end up with the initialisation half way. When MS decides to change the order of events in a future release, your VSIX must be changed. But at least this gives the option to run an existing VSIX in async package mode, loading the first solution properly.

Goodies
  • 1,951
  • 21
  • 26