Make Visual Studio auto reload solution when proje

2020-06-30 04:57发布

问题:

On the current project I am working on, there is, at the moment, a large churn of code, which means updating from source control can mean at times many csproj file changes. As we all know, VS2010 doesn't have a "Reload all" button, but you must reload each project and confirm each reload.

Is there a method where either the project is auto-reloaded or the IDE can detect this and ask for a solution reload?

回答1:

Finally found a solution:

http://lostechies.com/jimmybogard/2011/01/27/reloading-all-projects-with-vscommands/

Quoting from the site:

Quite often I’ll find myself working in situations where multiple projects have changed, and Visual Studio asks to reload them, one at a time. This happens when I’m working a lot with source control, and doing things like switching branches, performing merges, or just integrating upstream changes. I have to click “Reload” a million times for each project that changed on disk, and it’s quite annoying. On top of that, VS forgets which files I have open, so every file that I was working on gets closed.

I may be the last VS user to find out about this, but a free lite version of the VSCommands plugin is available on the Visual Studio Gallery that does just what I need – reload all changed projects at once, preserving which files I had open:



回答2:

It's a pain, but the best option I've found is to Close the solution before Getting the latest source code.

If there are more than two changed projects, it is faster to manually unload&reload the entire solution than it is to Get and wait for it to unload&reload the affected projects only - reloading projects is achingly slow (even disregarding having to click the OK button for every project that changed).

(In my mind the real question is: Why does it ask that question at all??? If you Get the latest source code, there is absolutely no sane reason why you would want to only use part of it. It's like a petrol station attendant saying "You've bought some fuel. Would you like me to now actually put it in your car, or shall I just pour it out on the ground?")



回答3:

Well, that doesn't work if your references paths changed in the csproj file and your using something like the sysinternals junction tool to change a symlink. E.g. tool switches D:\Projects symlink from D:\Baselines\1.0\Prjects to D:\Baselines\2.0\Projects , and because someone changed the folder structure between 1.0 and 2.0, your .csproj file suddenly points the dll path from ....\References\some.dll to ....\References\3rd-Party\some.dll . I know that is a special case, but happens (e.g. in my company).

There is an alternative solution though, one which I highly recommend as it has other benefits, too: the not-so-well-known VS 2010 Extension Solution Load Manager. It defers loading of Projects to the background, or until manually loaded, improving solution load time a lot for large solution files. It has this "reload solution" button in it's menu (unfortunatlely there seems to be no shortcut) which then reloads all solutions from scratch, skipping/backgroundloading the solutions you set. A Microsoft guy commented on his blog that they wanted to include something similar into VS 2010, but the feature didn't quite make it.

Sure, it may take longer then "just" one click and updating 100 documents, but it solved my problem of (relative) reference path changes, and gives a nice speed boost every time I open an at least medium sized solution.

Edit as of Oct 2013 VS2012 includes this functionality by default. At least the async loading stuff. The "don't load at all" functionality is unfortunately only possible by using manual "unload project" in VS2012. But as pr-project memory consumption did go down with VS2012, it's not that big of a deal anymore.



回答4:

If you have checked the option "detect when file is changed outside the environment" in the "Documents" section of options, projects and files are reloaded when changed. It works for me when switching branches in git.