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?
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,