【发布时间】:2022-01-18 21:47:42
【问题描述】:
我正在尝试将旧的 Visual Studio 扩展迁移到新的 2022 Studio。找到了一些名为“Community Visual Studio Toolkit”的精美解决方案,但遇到了一些问题。当我在用户打开某些解决方案时使用ProvideAutoLoad 属性加载我的扩展时,我无法访问我需要签署我的事件处理程序的WindowEvents。这是调试时的错误:https://snipboard.io/yUXIed.jpg
所以这是我使用的代码,这里我有错误:
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class MyPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await this.RegisterCommandsAsync();
VS.Events.WindowEvents.ActiveFrameChanged += WindowEvents_ActiveFrameChanged;
}
}
问题是我的旧实现适用于这段代码:
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
public sealed class MyPackage : ToolkitPackage
{
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await this.RegisterCommandsAsync();
// Getting `DTE2 dte` trough standard way...
dte.Events.WindowEvents.WindowActivated += WindowEvents_WindowActivated;
}
}
但是我不想在新的扩展版本中使用旧类型的代码,那么,在第一个实现示例中如何解决这个问题?
【问题讨论】:
标签: visual-studio-extensions visual-studio-2022