Can Visual Studio prompt before rebuilding?

后端 未结 4 533
半阙折子戏
半阙折子戏 2021-01-17 07:29

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

相关标签:
4条回答
  • 2021-01-17 08:11

    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.

    0 讨论(0)
  • 2021-01-17 08:14

    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.
    0 讨论(0)
  • 2021-01-17 08:16

    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.

    0 讨论(0)
  • 2021-01-17 08:22

    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 讨论(0)
提交回复
热议问题