28

Any way to have Visual Studio prompt before rebuilding, or any other way to make it easier to avoid hitting "Rebuild" instead of "Build"?

I've wasted countless hours when I right click on a project and select "Rebuild" on accident when I meant to click "Build".

This is for a native C++ solution.

2
  • I just hit F7 when I want to build. Granted, it does build the whole solution, but that is what you want usually. An alternative could be to set a shortcut for project-build, so you can avoid any mouse based confusion on that one.
    – Arne Mertz
    Feb 19, 2013 at 17:32
  • Yeah I guess I'll have to get in the habit of using F7 for building the entire solution. Though I do build single projects often in my case.
    – default
    Feb 19, 2013 at 21:42

4 Answers 4

44

Visual Studio 2010 allows for customization of the menus. You can remove the "Rebuild" item from the Project context menu. Or you may want to just move the "Rebuild" command away from the "Build" command so that you will be less likely to accidentally hit the wrong item.

From VS 2010,

  • Select the Tools Menu
  • Select Customize...
  • Select the Commands tab
  • Select the "Context menu" radio button and select "Project and Solution Context Menus | Project"
  • Select "Rebuild" and move it or remove it.
2
  • Although we answered the same way, I'm upvoting yours as it's your first answer. Keep them coming! :) Feb 19, 2013 at 17:52
  • Are you sure you didn't upvote because he's taller than you? ;)
    – user420442
    Feb 19, 2013 at 19:17
10

As far as I know, there is no way to enable a confirmation for performing a project or solution rebuild.

Your best option is to move or delete the "Rebuild" menu item on the context menu.

  1. Right click the menu/toolbar area in VS and select "Customize..."
  2. Click on the the "Commands" tab.
  3. Select the "Context menu" radio button.
  4. Find "Project and Solution Context Menus | Project" in the dropdown list.
  5. Click on the "Rebuild" menu item in the context menu representation and perform the desired action (delete, move up or down, begin a new group, etc.).

To reset the menu back to the default state, click the "Reset all" button.

3

Add a new sub-menu called "Rebuild"

Move (delete then add) the real Rebuild command to this new menu. Rename it "Sure" if you like.

0

You can use the following C# extension for my Visual Commander tool:

public class E : VisualCommanderExt.IExtension
{
    public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        events = DTE.Events;
        commandEvents = events.get_CommandEvents(null, 0);
        commands = DTE.Commands as EnvDTE80.Commands2;
        commandEvents.BeforeExecute += OnBeforeExecute;
    }

    public void Close()
    {
        commandEvents.BeforeExecute -= OnBeforeExecute;
    }

    private void OnBeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
    {
        string name = GetCommandName(Guid, ID);
        if (name.Contains("Rebuild"))
        {
            if (System.Windows.MessageBox.Show("Are you sure you want to Rebuild?", "Confirm", 
                System.Windows.MessageBoxButton.YesNo) != System.Windows.MessageBoxResult.Yes)
            {
                CancelDefault = true;
            }
        }
    }

    private string GetCommandName(string Guid, int ID)
    {
        if (Guid == null)
            return "null";
        try
        {
            return commands.Item(Guid, ID).Name;
        }
        catch (System.Exception)
        {
        }
        return "";
    }

    private EnvDTE.Events events;
    private EnvDTE.CommandEvents commandEvents;
    private EnvDTE80.Commands2 commands;
}

It asks to confirm all rebuild commands like Build.RebuildSolution, Build.RebuildSelection and Build.ProjectPickerRebuild.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.