回答編集履歴

1

ソースを短くしました。

2018/11/13 01:22

投稿

takabosoft
takabosoft

スコア8356

test CHANGED
@@ -10,49 +10,15 @@
10
10
 
11
11
  ```csharp
12
12
 
13
- public static EnvDTE.DTE GetCurrentDTE(IServiceProvider provider)
14
-
15
- {
16
-
17
- var vs = (EnvDTE.DTE)provider.GetService(typeof(EnvDTE.DTE));
18
-
19
- if (vs == null) throw new InvalidOperationException("DTE not found.");
20
-
21
- return vs;
22
-
23
- }
24
-
25
-
26
-
27
- public static EnvDTE.DTE GetCurrentDTE()
28
-
29
- {
30
-
31
- return GetCurrentDTE(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider);
32
-
33
- }
34
-
35
-
36
-
37
- /// <summary>
38
-
39
- /// This function is the callback used to execute the command when the menu item is clicked.
40
-
41
- /// See the constructor to see how the menu item is associated with this function using
42
-
43
- /// OleMenuCommandService service and MenuCommand class.
44
-
45
- /// </summary>
46
-
47
- /// <param name="sender">Event sender.</param>
48
-
49
- /// <param name="e">Event args.</param>
50
-
51
13
  private void MenuItemCallback(object sender, EventArgs e)
52
14
 
53
15
  {
54
16
 
17
+ IServiceProvider provider = (IServiceProvider)package;
18
+
55
- var dte = GetCurrentDTE();
19
+ var dte = (EnvDTE.DTE)provider.GetService(typeof(EnvDTE.DTE));
20
+
21
+
56
22
 
57
23
  if (dte.SelectedItems.Count > 0)
58
24
 
@@ -76,6 +42,4 @@
76
42
 
77
43
  参考:
78
44
 
79
- [Visual Studio 2015 を使用した VSPackage の作成について](https://blogs.msdn.microsoft.com/jpvsblog/2015/10/12/visual-studio-2015-vspackage/)
45
+ [Visual Studio 拡張機能から Visual Studio プロジェクトを弄っみる](https://qiita.com/tafuji/items/fd36c373f770d1ef4707)
80
-
81
- [How do you get the current solution directory from a VSPackage?](https://stackoverflow.com/questions/2336818/how-do-you-get-the-current-solution-directory-from-a-vspackage)