Visual Studio keeps building everything

2019-01-12 10:10发布

问题:

I have a large .sln file with many projects.

I just made a change in project A and it builds nine other projects that project A references, but that had no code change.

Is there a trick to speed this process up?

回答1:

Divide and conquer: Limit the amount of build time that goes on in your solution by creating additional solutions that contain logical subsets of projects you're working on. This limits your scope and will speed up builds.

See the The Partitioned Single Solution Model in this MSDN article: http://msdn.microsoft.com/en-us/library/ee817674.aspx

Key quote from the article:

Separate solution files allow you to work on smaller subsystems within your overall system 
but retain the key benefits of project references. Within each subsolution file, 
project references are used between constituent projects.


回答2:

This happens when a project has a file that doesn't really exist.
The project can't determine if the file was changed (because it's not there) so it rebuilds.

Simply look at all the files in the project, and search for the one that doesn't have an expandable arrow near it.



回答3:

Selecting 'build only' when right-clicking the project A should do the trick. I am not sure if there is a way to keep it from building referenced projects as well when building the solution (which is what the standard 'build' command does).



回答4:

Make sure your project dependencies are correct. Right click on the project and go to "Project Dependencies." Make sure that each project only depends on the minimal set of other projects that are needed to link.



回答5:

Change the build output verbosity to detailed and see what it says at the top. In my case, it told me the project wasn't up to date because of a file that was missing.



回答6:

Another thing to look for, because it just happened to me, is that if you synchronise your view using ClearCase while your solution is open and some of your code was updated by the synch, it sometimes sets the timestamps incorrectly on the files, so it keeps thinking your source files have been modified and compiling your project every time.

To fix this I had to close the solution and reopen it again, and it behaved as expected.