Can I force Visual Studio (2010) to do a “Save All

2019-07-05 19:56发布

问题:

I have a recurring frustration with Visual Studio 2010. I'll add a new file to a project, build, run tests - all good. Then I'll commit and push my changes (I'm using GitExtensions and GitHub)

Finally, I'll exit Visual Studio - and get asked if I want to save changes to MyProject.csproj. Sure enough, after saving changes, the .csproj file now shows local modifications in GitExtensions - which means the previous commit/push actually pushed broken code, because I'd pushed the new file without the corresponding .csproj file reference. All because Visual Studio doesn't actually save your .csproj file when you add new files to your project - although it seems to compile it quite happily without your changes being saved to disk yet...

Is there any way I can force Visual Studio to do a "save all" whenever I add a new file - or whenever I run some frequent command, like building the solution?

回答1:

Look under Tools --> Options --> Projects and Solutions --> Build And Run --> Before Building (Save all changes) for the option.

Later versions of VS (2012+) should always save your projects when building.