How can I enable/disable command in Visual Studio 2017 VSIX C# project

cristian leonardi

I'm developing an extension for Visual Studio 2017 using a C# VSIX project. I need to create a variable number of commands based on settings in a .ini file. I thought to create a maximum number of commands (because in a VSIX project every command needs a new .cs file), and enable only the commands written in the .ini file. Unfortunately I don't know how to disable a command. I need to enable the commands when a boolean becomes true.

I've seen that I need to use the OleMenuCommand class, but I do not have Initialize() and StatusQuery() methods. How can I dynamically enable my commands?

Ionut Enache

To enable/disable commands in Visual Studio you can subscribe to the BeforeQueryStatus event of your OleMenuCommand:

myOleMenuCommand.BeforeQueryStatus += QueryCommandHandler;

private void QueryCommandHandler(object sender)
{
        var menuCommand = sender as Microsoft.VisualStudio.Shell.OleMenuCommand;
        if (menuCommand != null)
            menuCommand.Visible = menuCommand.Enabled = MyCommandStatus();
}

A possible implementation of MyCommandStatus() method can be:

public bool MyCommandStatus()
{
    // do this if you want to disable your commands when the solution is not loaded
    if (false == mDte.Solution.IsOpen)
      return false;

    // do this if you want to disable your commands when the Visual Studio build is running
    else if (true == VsBuildRunning)
      return false;

    // Write any condition here

    return true;

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I find out what type of c# project I'm using in Visual Studio 2017?

From Dev

Publishing Visual Studio 2017 multi-project VSIX to the marketplace

From Java

How can I use C# 8 with Visual Studio 2017?

From Dev

How can I run a visual studio project from the mac command line?

From Dev

Visual Studio 2017 VSIX with ASP.NET Core 2 Web Application template just installs a blank project

From Java

How can I run NUnit tests in Visual Studio 2017?

From Java

How can I disable live code analysis in Visual Studio 2017?

From Dev

How can I add and use image in Visual Studio 2017?

From Dev

How do I install a VSIX file in Visual Studio?

From Dev

How can I view the main form in a Visual Studio Visual C++ Win32 Project so I can edit it?

From Dev

How can I view the main form in a Visual Studio Visual C++ Win32 Project so I can edit it?

From Dev

How can I use RTMPDump from a Visual Studio C++ project?

From Dev

How can I create a C++ project in Visual Studio 2010 Ultimate

From Dev

How can I use RTMPDump from a Visual Studio C++ project?

From Dev

How can I get the build number of a Visual Studio project to increment?

From Dev

How can I share a Visual Studio project across computers easily?

From Java

How can I rename a project folder from within Visual Studio?

From Dev

How can I get with PowerShell the project version in Visual Studio?

From Dev

How can I check for Visual Studio updates via the command line?

From Dev

How can I check for Visual Studio updates via the command line?

From Dev

How do I pass args while debugging a node.js project in Visual Studio 2017?

From Java

How to uninstall .vsix Visual Studio Extensions?

From Dev

How can I delete a Visual Studio project outside of Visual Studio without wreaking havoc on the solution?

From Dev

How to pass the /unsafe flag to the C# compiler when building an SSDT Project with Visual Studio 2017

From Dev

How do I make a Visual Studio 2015 C++ project compatible with Visual Studio 2010?

From Dev

Where is Visual Studio 2013 Extensibility VSIX Project Template

From Java

Can I download the Visual C++ Command Line Compiler without Visual Studio?

From Dev

How to download full Visual Studio 2017 Community with command line enabled?

From Java

How can I refresh the list of remote branches in my Visual Studio 2017 Team Explorer panel?

Related Related

  1. 1

    How can I find out what type of c# project I'm using in Visual Studio 2017?

  2. 2

    Publishing Visual Studio 2017 multi-project VSIX to the marketplace

  3. 3

    How can I use C# 8 with Visual Studio 2017?

  4. 4

    How can I run a visual studio project from the mac command line?

  5. 5

    Visual Studio 2017 VSIX with ASP.NET Core 2 Web Application template just installs a blank project

  6. 6

    How can I run NUnit tests in Visual Studio 2017?

  7. 7

    How can I disable live code analysis in Visual Studio 2017?

  8. 8

    How can I add and use image in Visual Studio 2017?

  9. 9

    How do I install a VSIX file in Visual Studio?

  10. 10

    How can I view the main form in a Visual Studio Visual C++ Win32 Project so I can edit it?

  11. 11

    How can I view the main form in a Visual Studio Visual C++ Win32 Project so I can edit it?

  12. 12

    How can I use RTMPDump from a Visual Studio C++ project?

  13. 13

    How can I create a C++ project in Visual Studio 2010 Ultimate

  14. 14

    How can I use RTMPDump from a Visual Studio C++ project?

  15. 15

    How can I get the build number of a Visual Studio project to increment?

  16. 16

    How can I share a Visual Studio project across computers easily?

  17. 17

    How can I rename a project folder from within Visual Studio?

  18. 18

    How can I get with PowerShell the project version in Visual Studio?

  19. 19

    How can I check for Visual Studio updates via the command line?

  20. 20

    How can I check for Visual Studio updates via the command line?

  21. 21

    How do I pass args while debugging a node.js project in Visual Studio 2017?

  22. 22

    How to uninstall .vsix Visual Studio Extensions?

  23. 23

    How can I delete a Visual Studio project outside of Visual Studio without wreaking havoc on the solution?

  24. 24

    How to pass the /unsafe flag to the C# compiler when building an SSDT Project with Visual Studio 2017

  25. 25

    How do I make a Visual Studio 2015 C++ project compatible with Visual Studio 2010?

  26. 26

    Where is Visual Studio 2013 Extensibility VSIX Project Template

  27. 27

    Can I download the Visual C++ Command Line Compiler without Visual Studio?

  28. 28

    How to download full Visual Studio 2017 Community with command line enabled?

  29. 29

    How can I refresh the list of remote branches in my Visual Studio 2017 Team Explorer panel?

HotTag

Archive