Automatically Build after save, for Visual Studio 2015?

前端 未结 3 1541
无人及你
无人及你 2020-12-19 12:45

When using Visual Studio, I\'d like it to build my projects continuously. That is, after every save, kick off a build. I tend to work on large (35+ project) solutions, so ha

相关标签:
3条回答
  • 2020-12-19 13:06

    I started developing a new open source extension that is called BuildOnSave and does exactly that: It builds the current solution or startup project when a file is saved.

    It's available on the Visual Studio Extension Gallery: https://visualstudiogallery.msdn.microsoft.com/2b31b977-ffc9-4066-83e8-c5596786acd0

    May be you can give it a try. I would very much appreciate feedback.

    0 讨论(0)
  • 2020-12-19 13:08

    There is a sample extension for Visual Commander that runs Cppcheck on the saved file. You can replace Cppcheck with DTE.ExecuteCommand("Build.BuildSolution");

    0 讨论(0)
  • 2020-12-19 13:11

    Building on Sergey Vlasov's answer, here's the modified version of the Visual Commander extension;

    using EnvDTE;
    using EnvDTE80;
    
    public class E : VisualCommanderExt.IExtension
    {
        private EnvDTE80.DTE2 DTE;
        private EnvDTE.Events events;
        private EnvDTE.DocumentEvents documentEvents;
        private EnvDTE.BuildEvents buildEvents;
    
        public void SetSite(EnvDTE80.DTE2 DTE_, Microsoft.VisualStudio.Shell.Package package)
        {
            DTE = DTE_;
            events = DTE.Events;
            documentEvents = events.DocumentEvents;
            buildEvents = events.BuildEvents;
    
            buildEvents.OnBuildProjConfigDone += OnBuildProjectDone;
            documentEvents.DocumentSaved += OnDocumentSaved;
        }
    
        public void Close()
        {
            documentEvents.DocumentSaved -= OnDocumentSaved;
            buildEvents.OnBuildProjConfigDone -= OnBuildProjectDone;
        }
    
        private void OnDocumentSaved(EnvDTE.Document doc)
        {
            if(doc.Language == "CSharp")
            {
                var sb = DTE.Solution.SolutionBuild;
                sb.Build();
            }
        }
    
        private void OnBuildProjectDone(string project, string projectConfig, string platform, string solutionConfig, bool success)
        {
            //OutputString("Project " + project + " " + (success ? "build" : "failed to build"));   
        }
    
        private void OutputString(string line)
        {
            GetOutputPane().OutputString(line + System.Environment.NewLine);
        }
    
        private EnvDTE.OutputWindowPane GetOutputPane()
        {
            string cppcheckPaneName = "VCmd"; 
            foreach (EnvDTE.OutputWindowPane pane in 
                DTE.ToolWindows.OutputWindow.OutputWindowPanes)
            {
                if (pane.Name == cppcheckPaneName)
                    return pane;
            }
            return DTE.ToolWindows.OutputWindow.OutputWindowPanes.Add(cppcheckPaneName);
        }
    }
    
    0 讨论(0)
提交回复
热议问题