title: How to load a ModelingPackage (DSL-Tools) asynchronously in Visual Studio 2019?
body: <p>I have a DSL-tools project where I use <code>[ProvideAutoLoad]</code> because it adds a set of menu commands to Visual Studio to allow the user to transform code (we have lots of text templates), and few other things.</p>
  
  <p>Since VS2019 does <a href="https://devblogs.microsoft.com/visualstudio/updates-to-synchronous-autoload-of-extensions-in-visual-studio-2019/" rel="nofollow noreferrer">not allow to autoload sync packages anymore</a>, I get that annoying warnings even when the option to allow autoload is on.</p>
  
  <p>Apparently Microsoft has no plans to provide an async version of <code>ModelingPackage</code> (I am in fact begining to question if their not in the way to descontinue DSL-tools alltogether).</p>
  
  <p>As anyone found a way of working around this?</p>
  
  <p>I have tried to use another package - built as <code>AsyncPackage</code> - so that one would load my DSL-tools package on <code>InitializeAsync()</code> but I end up with all sorts of exceptions using the <code>IVsShell</code> service.</p>
  
  <pre><code>protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress&lt;VSShell.ServiceProgressData&gt; progress)
  {
      // Default behavior
  
      await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(false);
  
      // Load the service designer package
  
      this.EnsureDesignerPackage();
  
      // Switche to the UI thread
  
      await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
  
      // Menu commands
  
      this.InitializeMenuCommands();
  }
  
  private void EnsureDesignerPackage()
  {
      // Package already loaded?
  
      if (!this.IsDesignerPackageLoaded())
      {
          this.LoadDesignerPackage();
      }
  }
  
  private bool IsDesignerPackageLoaded()
  {
      // Package identifier
  
      Guid packageId = new Guid(GlobalConstants.ServiceDesignerPackageId);
  
      // Is loaded?
  
      IVsShell service = this.VsShellService;
  
      int hr = this.VsShellService.IsPackageLoaded(ref packageId, out IVsPackage package);
      if (ErrorHandler.Succeeded(hr) &amp;&amp; package != null)
      {
          return true;
      }
  
      // Default result
  
      return false;
  }
  
  private void LoadDesignerPackage()
  {
      // Package identifier
  
      Guid packageId = new Guid(GlobalConstants.ServiceDesignerPackageId);
  
      // Not loaded?
  
      int hr = this.VsShellService.IsPackageLoaded(ref packageId, out IVsPackage package);
      if (hr != VSConstants.S_OK || package == null)
      {
          // Load
  
          hr = this.VsShellService.LoadPackage(ref packageId, out package);
          if (ErrorHandler.Failed(hr))
          {
              string message = "Service designer loading failed: {0}.".Format().With(hr);
              this.ShowException(message);
          }
      }
  }
  </code></pre>