Добавление пункта меню при щелчке правой кнопкой мыши в обозревателе решений Visual Studio - PullRequest
0 голосов
/ 17 июня 2020

Я создаю расширение Visual Studio, чтобы сократить для себя какой-то обыденный код. Я пытаюсь добавить меню расширения при щелчке правой кнопкой мыши в проводнике проекта, он должен затем запустить форму после выполнения действия

private CreateCrud(Package package)
{
        if (package == null)
        {
            throw new ArgumentNullException("package");
        }

        this.package = package;

        OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
        if (commandService != null)
        {
            var menuCommandID = new CommandID(CommandSet, CommandId);
            var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
            commandService.AddCommand(menuItem);
        }
}

В моем классе я вызываю событие Initialize нормально.

  protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress) {
        // When initialized asynchronously, the current thread may be a background thread at this point.
        // Do any initialization that requires the UI thread after switching to the UI thread.

        CreateCrud.Initialize(this);
        await base.InitializeAsync(cancellationToken, progress);
        Dte = await GetServiceAsync(typeof(DTE)) as DTE2;
        Instance = this;
        Logger.Initialize(this, "Ef Core CRUD Generator");
        await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
    }

    #endregion
}

Но по какой-то причине оно не помещает его в меню.

/// <summary>
/// Initializes the singleton instance of the command.
/// </summary>
/// <param name="package">Owner package, not null.</param>
public static void Initialize(Package package)
{
    Instance = new CreateCrud(package);
}

Я скопировал код из другого открытого источника extension, в которую включен этот гид. Мне нужно сгенерировать guid specifici c для моей программы, поэтому он не отображается.

public const string PackageGuidString = "9615efc3-3943-4297-9fdf-0ca3680b1d1f";

Это код, который должен запускать форму

private void MenuItemCallback(object sender, EventArgs e)
{
   // Create the window with the unused ID.
   using (DpiAwareness.EnterDpiScope(DpiAwarenessContext.SystemAware))
   {
      var obj = new frmExtension();
       obj.Show();
   }    


}

Когда я отлаживаю, я перехожу в свой экземпляр Visual Studio:

Запустить внешнюю программу с помощью: C: \ Program Files (x86) \ Microsoft Visual Studio \ 2019 \ Community \ Common7 \ IDE \ devenv .exe

Аргументы командной строки: / rootsuffix Exp

Но он не прикреплен к меню

...