重现步骤:
- 打开 Visual Studio 2017。选择文件..新建..项目..
- 从“新建项目”对话框中,选择“扩展性.. VSIX 项目..
- 从解决方案资源管理器中选择新项目。右键单击并添加.. 新项目.. 可扩展性.. 自定义命令..
- 您现在拥有从标准模板构建的完整自定义命令。在调试器中运行它。您将获得 Visual Studio 的实验性实例。从菜单中,选择工具...调用 Command1...您的自定义命令有效!
- 点击“确定”并退出 Visual Studio 的实验实例。
- 现在,回到原始解决方案,单击工具.. NuGet 包管理器.. 管理解决方案的 NuGet 包...
- 在更新选项卡中,您将看到模板中包含的标准包的许多更新。全部选择并更新它们。重复,直到您的所有软件包都已更新。在此过程中,您可能需要重新启动 VS。
再次构建您的 VSIX 包。您可能必须取消围绕此语句的警告:
public static async Task InitializeAsync(AsyncPackage package) { // Verify the current thread is the UI thread - the call to AddCommand in Command1's constructor requires // the UI thread. #pragma warning disable VSTHRD109 // Switch instead of assert in async methods ThreadHelper.ThrowIfNotOnUIThread(); #pragma warning restore VSTHRD109 // Switch instead of assert in async methods OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService; Instance = new Command1(package, commandService); }
再次调试 VSIX 包。
- 选择工具...调用命令 1...
- 您收到错误消息:“Command1Package”包未正确加载。
如果按照 %AppData% 目录的说明阅读活动日志,您将看到无法加载 Microsoft.VisualStudio.Threading 15.8.0.0 程序集。
无法加载文件或程序集“Microsoft.VisualStudio.Threading, Version=15.8.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。该系统找不到指定的文件。System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.VisualStudio.Threading,版本=15.8.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。