Can Visual Studio prompt before rebuilding?

后端 未结 4 532
半阙折子戏
半阙折子戏 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.

提交回复
热议问题