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
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.
There is a sample extension for Visual Commander that runs Cppcheck on the saved file. You can replace Cppcheck with DTE.ExecuteCommand("Build.BuildSolution");
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);
}
}