C# Visual Studio扩展:从装饰中获取包
我正在开发一个Visual Studio扩展,由以下部分组成:C# Visual Studio扩展:从装饰中获取包,c#,visual-studio,visual-studio-extensions,C#,Visual Studio,Visual Studio Extensions,我正在开发一个Visual Studio扩展,由以下部分组成: 菜单和一系列命令 工具窗口 一个或多个textview装饰 AysncPackage的自定义实现 现在,虽然工具窗口和命令要么由我的扩展的AsyncPackage连接,要么有一个句柄,但我不知道如何从一个或多个文本装饰中获得自同一AsyncPackage的句柄 例如,“我的工具”窗口扩展了ToolWindowPane,它通过包的ProvideToolWindow属性与包挂钩。我的命令是在包本身内部构造的,因此将句柄传递给AsyncP
有什么帮助吗?这是个棘手的问题!您必须让IVsShell根据与包关联的GUID检索包,然后将其强制转换到接口(或IPackage的基本接口)
private IMyPackageInterface _myPackage;
//let's get our hands on that package
var vsShell = (IVsShell) ServiceProvider.GlobalProvider.GetService(typeof(IVsShell));
if (vsShell == null)
{
throw new NullReferenceException();
}
if (vsShell.IsPackageLoaded(PackageGuid, out var myPossiblePackage)
== Microsoft.VisualStudio.VSConstants.S_OK) {
_myPackage = (IMyPackageInterface)myPossiblePackage;