How to automatically save project file after a new file include in Visual Studio?
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.
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.
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();
}
}
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.
精彩评论