获取所选文件并使用 IVsSingleFileGenerator

发布于 2024-10-27 21:36:03 字数 1087 浏览 1 评论 0原文

我正在尝试将几个新功能添加到我为我们公司开发的包中。这些功能之一是根据解决方案资源管理器中选择的文件和选择的菜单选项创建一个新文件。我已经创建了解决方案资源管理器上的动态菜单项,看起来我需要使用 IVsSingleFileGenerator,如此示例中所示。

我遇到的麻烦是获取我选择的文件,然后读取它或将其传递到单个文件生成器中。 我宁愿从此上下文菜单生成文件,而不是从自定义工具操作生成文件

看起来这将为我提供文件的路径

UIHierarchy solutionExplorer = _applicationObject.ToolWindows.SolutionExplorer;

          var items = solutionExplorer.SelectedItems as Array;

          if (items == null || items.Length != 2)

          {

            return;

          }

          String strFile1 = String.Empty;

          UIHierarchyItem item1 = items.GetValue(0) as UIHierarchyItem;

          foreach (UIHierarchyItem hierarchyItem in items)

          {

            ProjectItem prjItem = hierarchyItem.Object as ProjectItem;

            string prjPath = prjItem.Properties.Item("FullPath").Value.ToString();

          }

,然后我可以使用该路径将其传递到 ivs 单文件生成器的生成函数中。

这是最好的方法吗?

I am trying to add several new functions to a package I developed for our company. One of these functions is to create a new file based on the file selected in the solution explorer and the menu option selected. I have created my dynamic menu items that are on the solution explorer and it looks like I need to use IVsSingleFileGenerator as shown in this sample.

The trouble I am having is getting the file I have selected and either reading it or passing it into a single file generator.
I would rather generate the file from this context menu than from a custom tool action

Looks like this will get me the path of the file

UIHierarchy solutionExplorer = _applicationObject.ToolWindows.SolutionExplorer;

          var items = solutionExplorer.SelectedItems as Array;

          if (items == null || items.Length != 2)

          {

            return;

          }

          String strFile1 = String.Empty;

          UIHierarchyItem item1 = items.GetValue(0) as UIHierarchyItem;

          foreach (UIHierarchyItem hierarchyItem in items)

          {

            ProjectItem prjItem = hierarchyItem.Object as ProjectItem;

            string prjPath = prjItem.Properties.Item("FullPath").Value.ToString();

          }

which I can then use to pass into the generate function of the ivs single file generator.

Is this the best approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小兔几 2024-11-03 21:36:03

我还将这个问题发布到 msdn 论坛:
VSX 获取所选文件并使用IVsSingleFileGenerator

我最终使用 IPyIntegration 示例来弄清楚我需要做什么。

I also posted this question to the msdn forums at:
VSX getting the selected file and using IVsSingleFileGenerator

I ended up using the IPyIntegration sample to figure out what i needed to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文