I have a DSL-tools project where I use [ProvideAutoLoad]
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.
Since VS2019 does not allow to autoload sync packages anymore, I get that annoying warnings even when the option to allow autoload is on.
Apparently Microsoft has no plans to provide an async version of ModelingPackage
(I am in fact begining to question if their not in the way to descontinue DSL-tools alltogether).
As anyone found a way of working around this?
I have tried to use another package - built as AsyncPackage
- so that one would load my DSL-tools package on InitializeAsync()
but I end up with all sorts of exceptions using the IVsShell
service.
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<VSShell.ServiceProgressData> 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) && 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);
}
}
}