15

Visual Studio 2012 ソリューション エクスプローラーで、右クリック => メニューの追加にメニュー項目を追加したいと考えています。カスタム項目をクリックすると、テンプレートを使用してプロジェクトを追加できます。それを行うために Visual Studio アドインを開発しましたが、問題が発生します。右クリック メニューにメニュー項目を追加できますが、要件を満たすことができません。

  1. メニュー項目は「追加」のサブメニューである必要があります。ルート項目ではありません。

  2. また、「エリア」という名前のフォルダーを右クリックしたときにのみメニュー項目を表示する必要があります。他のフォルダを右クリックしたときに表示したくありません。

これが私のOnConnection関数コードです。要件を満たすように変更するにはどうすればよいですか。

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = ((AddIn)addInInst);
        if (connectMode == ext_ConnectMode.ext_cm_UISetup)
        {
            object[] contextGUIDS = new object[] { };
            Commands2 commands = (Commands2)_applicationObject.Commands;

            //Place the command on the tools menu.
            //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
            var bars=((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars);

            Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = bars["MenuBar"];

            //Find the Tools command bar on the MenuBar command bar:
            //CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
            //CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
            // get popUp command bars where commands will be registered.
            CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
            //CommandBar vsBarItem = cmdBars["Item"]; //the pop up for clicking a project Item
            CommandBar vsBarFolder = cmdBars["Web Project Folder"];
            CommandBar vsBarWebFolder = cmdBars["Web Folder"];

            //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
            //  just make sure you also update the QueryStatus/Exec method to include the new command names.
            try
            {
                //Add a command to the Commands collection:
                Command command = commands.AddNamedCommand2(_addInInstance, "ModuleAddin", "Add a Project", "Executes the command for ModuleAddin", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
                //Add a control for the command to the tools menu:
                if (command != null)
                {
                    //command.AddControl(toolsPopup.CommandBar, 1);
                    command.AddControl(vsBarFolder);
                    //CommandBarButton button = (CommandBarButton)command.AddControl(vsBarFolder, 3);
                    //button.BeginGroup = true;
                }
            }
            catch (System.ArgumentException argEx)
            {
                System.Diagnostics.Debug.Write("Exception in HintPaths:" + argEx.ToString());
            }
        }
    }
4

1 に答える 1

37

これにはアドインは必要ありません。

リンク: http://nickmeldrum.com/blog/how-to-run-powershell-scripts-from-solution-explorer-in-visual-studio-2010

ブログ記事をコピペ...

ステップ 1: 外部ツールとして「run powershell script」を追加する

  1. Visual Studio で次のメニューに移動します: ツール | ツール | 外部ツール
  2. 「追加」ボタンをクリック
  3. 次のフォーム値を追加します。

    • タイトル: 「出力ウィンドウで Powershell スクリプトを実行する」
    • コマンド: 「C:\windows\system32\windowspowershell\v1.0\powershell.exe」
    • 引数: " -file "$(ItemPath)"
    • 初期ディレクトリ: "$(ItemDir)"
    • 「出力ウィンドウを使用」にチェックを入れる
    • (Close on exit が自動的にオンになります)
  4. 「適用」ボタンをクリックします

  5. 「追加」ボタンをクリック

  6. 次のフォーム値を追加します。

    • タイトル: 「VS の外部で powershell スクリプトを実行する」
    • コマンド: 「C:\windows\system32\windowspowershell\v1.0\powershell.exe」
    • 引数: " -file "$(ItemPath)"
    • 初期ディレクトリ: "$(ItemDir)"
    • 「出力ウィンドウを使用する」にチェックを入れないでください
    • 「終了時に閉じる」にチェックを入れる
  7. 「OK」ボタンをクリック

それらは次のようになります。 >

ステップ 2: 奇妙なステップ、信じてください!

外部ツール リストのインデックス位置を確認してください。私のデフォルトでは、位置は 6 と 7 です (デフォルトでは Create GUID が 1 番だと思います!)

ステップ 3: コンテキスト メニューに接続する

  1. メニューに移動します: ツール | カスタマイズ | コマンド
  2. 「コンテキストメニュー」ラジオオプションをクリックします
  3. 「Project and Solution Context Menus | Item」まで下にスクロールします (悪夢のような長いメニューです。「Proj」と入力して、おおよそ適切な場所に移動します)。
  4. 「コマンドを追加」ボタンをクリック
  5. カテゴリを選択します: 「ツール」とコマンド: 「外部コマンド 7」 (または「奇妙なステップ 2」から取得した位置は何でも)
  6. 「OK」ボタンを押す
  7. 次に、2 番目のコマンドを設定します。
  8. カテゴリを選択します: 「ツール」とコマンド: 「外部コマンド 8」 (または他のものに対するあなたの位置は何でも)
  9. もう一度「OK」ボタンを押す
  10. 注文に満足するまでそれらを移動します(通常、「Open With ...」の下のどこかに配置します)>

ステップ 4: キーボード ショートカットを追加する

  1. メニューに移動します: ツール | オプション
  2. 環境を選択 | 鍵盤部
  3. リストで Tools.ExternalCommandN 項目を見つけます (再び悪夢のような長いリストです。「Tools」と入力すると、大まかにそこに戻ることができます)。
  4. 各コマンドのショートカット キーを選択CTRL SHIFT Pします。CTRL SHIFT ALT P

オハイ

于 2016-03-11T22:34:00.310 に答える