首页 > 解决方案 > VSIX:有没有比这更好的方法来获取 Visual Studio 活动文档?

问题描述

我正在升级旧的 Visual Studio 工具集以使用新的可扩展性框架。当我使用新模板时,我得到了一组只需要Microsoft.VisualStudio.Shell.15.0NewtonSoft.Json的干净引用。然后我开始引入我的旧代码。我尝试做的第一件事是获取运行自定义命令的环境。我使用以下代码:

    // The VS Package provides services for examining the Visual Studio environment.
    InsertModuleHeaderCommand.serviceProvider = package as IServiceProvider;
    InsertModuleHeaderCommand.environment = InsertModuleHeaderCommand.serviceProvider.GetService(typeof(DTE)) as DTE2;
    Assumes.Present(InsertModuleHeaderCommand.environment);

此时我需要引入envdteenvdte80。然后我收到一条关于清理互操作的消息。这看起来又丑又旧。有没有更好、更新的方法来获取ActiveDocument

标签: visual-studio-2017vsixvs-extensibility

解决方案


推荐阅读