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
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.
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,
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.
To reset the menu back to the default state, click the "Reset all" button.
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.