visual-studio-2012cppcheck

How can I run an external command on file save in Visual Studio?


I'm reading this article on integrating Cppcheck into VS: Poor Man’s Visual Studio Cppcheck Integration

I want to run the check upon saving the file, which is covered in the article. But, the article refers to Macros IDE, which, apparently, was taken out of VS 2012. Is there any other way to do it?


Solution

  • Using Mark Hall's answer, I installed and used Visual Commander to do something similar. This is my extension, that runs the first external tool when files in my project ("my-project") are saved:

    using EnvDTE;
    using EnvDTE80;
    
    public class E : VisualCommanderExt.IExtension
    {
        public void SetSite(EnvDTE80.DTE2 DTE_, Microsoft.VisualStudio.Shell.Package package)
        {
            DTE = DTE_;
            events = DTE.Events;
            documentEvents = events.DocumentEvents;
            documentEvents.DocumentSaved += OnDocumentSaved;        
        }
    
        public void Close()
        {
            documentEvents.DocumentSaved -= OnDocumentSaved;
        }
    
        private void OnDocumentSaved(EnvDTE.Document doc)
        {
            if(doc.Path.ToLower().Contains("my-project")) DTE.ExecuteCommand("Tools.ExternalCommand1");
        }
    
        private EnvDTE80.DTE2 DTE;
        private EnvDTE.Events events;
        private EnvDTE.DocumentEvents documentEvents;
    }