Visual Studio 可扩展性:为每个 UI 上下文的 Package.cs 提供自动加载 [英] Visual Studio Extensibility: ProvideAutoLoad for Package.cs for every UI Context
问题描述
我的目标是创建一个Visual Studio 扩展性",将Npm 安装"上下文菜单项添加到 package.json 文件中.
My goal is to create a "Visual Studio Extensibility" which adds a "Npm install" Context Menu Item to a package.json file.
到目前为止,如果我打开一个解决方案,这很有效,因为我已经将 [ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.SolutionExists)]
属性添加到 Package 类.
So far, this works great if I open a solution, because I've added the [ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.SolutionExists)]
attribute to the Package class.
但是如果我打开一个网站(文件->打开->网站...),它就不起作用.您知道如何为每个 UI 上下文自动加载 Package.cs 吗?
But it's not working if I open a Web Site (File->Open->Web Site...). Do you have any idea, how I can AutoLoad the Package.cs for every UI Context?
进一步调查后的更多信息:如果我将网站另存为解决方案,则会调用初始化"方法.但是 package.json 的 MenuItem 的 BeforeQueryStatus 没有被调用.解决方案结构如下所示:
More information after further investigation: If I save the Web Site as a Solution, the "Initialize"-Method is called. But the BeforeQueryStatus of the MenuItem of package.json is not called. The solution structure looks like this:
-Solution
-project
-package.json
如果我将 package.json 直接添加到解决方案中,则会出现上下文菜单项.结构:
If I add the package.json directly into the solution, the Context Menu Item appears. Structure:
-Solution
-Solution Items
-package.json
-project
有什么想法吗?
推荐答案
将以下代码添加到您的包定义中:
Add the below code to your package definition:
[ProvideAutoLoad(VSConstants.UICONTEXT.NoSolution_string)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasSingleProject_string)]
您的包应该在所有情况下都能加载.
Your package should load in all scenarios.
这篇关于Visual Studio 可扩展性:为每个 UI 上下文的 Package.cs 提供自动加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!