33

Working with Visual Studio 2010 here, but the behavior has been the same since the dawn of time - is there a way to force the IDE to automatically save the project file after doing an "Include in project" on new files? Folks new to VS don't quickly get in the habit of Ctrl+Shift+S after every one of these operations, leading to multiple repo commits when we discover assets missing from our bundled webapps.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Thomas H
  • 902
  • 9
  • 18
  • Does AnkhSVN do what you need? – GregC Apr 21 '11 at 17:08
  • Haven't looked at Ankh in a long, long time, but will check it out – Thomas H Apr 21 '11 at 17:19
  • +1 for effort to get out of the rat race that is the test-code-refactor-commit cycle. – GregC Apr 21 '11 at 17:24
  • Maybe if AnkhSVN does *not* do what you need, it might be worth checking out if VisualSVN does what you need — do check out the pros and cons; for some face-offs (perhaps a little old), e.g. look here: [SVN in Visual Studio](http://stackoverflow.com/questions/423687/which-plugin-do-you-use-for-svn-in-visual-studio) and [VisualSVN or AnkhSVN?](http://stackoverflow.com/questions/102324/which-would-you-rather-use-visualsvn-or-ankhsvn) – mousio Apr 24 '11 at 09:37
  • What source control are you using, BTW. – John Saunders Oct 15 '11 at 20:45
  • 1
    Great, Ctrl+Shift+S is all I want – h--n Jan 30 '12 at 15:03

3 Answers3

21

I used to run into this all the time and it was very annoying. The solution that I use is to re-map CTRL+S to File.SaveAll since I'm already using source control. However, this doesn't help new VS installs that haven't had this set up.

TheCloudlessSky
  • 18,608
  • 15
  • 75
  • 116
7

You can write an add in to achieve this. I'm still working the bugs out though. Extending VS is painful.

some excerpts:

    public class Connect : IDTExtensibility2
{
    private AddIn _addInInstance;
    private DTE2 _applicationObject;
    private Events2 events;

    public void OnStartupComplete(ref Array custom)
    {
        events = _applicationObject.Events as Events2;
        events.ProjectItemsEvents.ItemAdded += SolutionEvent;
        events.ProjectItemsEvents.ItemRemoved += SolutionEvent;
        events.ProjectItemsEvents.ItemRenamed += 
            new _dispProjectItemsEvents_ItemRenamedEventHandler(
                                    ProjectItemsEvents_ItemRenamed);
    }

    void ProjectItemsEvents_ItemRenamed(ProjectItem projectItem, 
                                        string OldName)
    {
        Save(projectItem);
    }

    private void SolutionEvent(ProjectItem projectItem)
    {
        Save(projectItem);
    }

    void Save(ProjectItem projectItem)
    {
        if (!projectItem.ContainingProject.Saved)
            projectItem.ContainingProject.Save();
    }
}
Kjartan
  • 18,591
  • 15
  • 71
  • 96
Sam
  • 1,725
  • 1
  • 17
  • 28
  • Seems to be exactly what I need (also having problems with regularly missing project changes in my Git commits). Any chance you have published this in full somewhere? – Xavier Poinas Mar 27 '12 at 01:11
  • No. I had weird issues trying to distribute it. It just wouldn't work on anyone else's PC. Obviously I was doing something stupid but never figured out what. – Sam Apr 04 '12 at 05:12
  • How would I go about implementing this as an addin? Would it work in VS 11? – Mike B Oct 11 '12 at 17:59
1

I think this was "by-design", so that you can prototype something without ever saving to disk. I agree that it should be an option.

In fact, if you're working on a project that's backed by a repository, it should save by default. If there's no associated repository, it should keep in memory, by default.

GregC
  • 7,737
  • 2
  • 53
  • 67
  • 1
    When using TFS as the source control, it automatically does "add to source control", though still doesn't save the project (or solution) files. I don't know if other integrated source control is the same. – John Saunders Oct 15 '11 at 20:46
  • In previous versions (at least in 2010), doing a compare operation would warn you that it requires saving the file to disk. Now I just feel like I'm going crazy when my changes don't show up in the differences (using 2015). – Elaskanator Jun 29 '18 at 21:16