Visual Studio Builds Projects Every Time I Run

2019-01-26 05:04发布

I have a .NET solution in Visual Studio 2010 with a bunch of projects. Up until recently, when I would run the startup project from within the IDE, projects would only build if changes had been made to the code in either the startup project or one of the dependency projects.

About two weeks ago I noticed that every time I run the startup project, Visual Studio builds all projects, which takes about seven minutes. Needless to say this is taking a large amount of time out of my day, and I've tried my best to look online for solutions, but have yet to find any solutions that address my specific problem.

A few additional pieces of information - the same problem began happening to everyone else on my team around the same time that I began experiencing this issue.

We are also using a source code repository. Since we didn't change any settings in Visual Studio, my suspicion is that someone inadvertently changed something in the source code for some project that now requires all projects to build every time.

Any suggestions would be greatly appreciated.

7条回答
Animai°情兽
2楼-- · 2019-01-26 05:30

Tools -> Options -> Project and Solutions -> Build and Run

Set your output verbosity to "Diagnostic". After doing another build, examine the output window. At the beginning of each project build, the build system will tell you which dependency is causing the project to be built.

(In my case, it was an .ico file that accidentally got set to Build Action: Resource and Copy To Output: Copy if newer. Very hard to find.)

查看更多
做个烂人
3楼-- · 2019-01-26 05:33

If Visual Studio is requiring a full build every time I would first be checking my settings (already mentioned) and then I would check the conditions VS uses to identify what needs to be built. I know VS checks timestamps on all input files when checking what needs to be built. I've seen cases where a linked generated file causes all downstream dependents to build every time, even though the content of the generated file was the same. Here's a link to MSDN incremental builds.

http://msdn.microsoft.com/en-us/library/ms171483.aspx

I'm not sure if there are other conditions VS uses to identify projects that need to be built.

查看更多
唯我独甜
4楼-- · 2019-01-26 05:34

I'll share the best answer i've found here on stackoverflow and combined with matt smith's accepted answer here, i´ve reached the root cause of my problem:

By configuring Visual Studio to log the build output in a "Diagnostic" manner, as explained in this answer: https://stackoverflow.com/a/29649259/2740778, the very first line on the output explains why MSBuild determines to rebuild a project.

So, if you have, let's say 3 projects into a solution:

  • Library0
  • Library1
  • Application

referenced this way: Application references Library1 and this one references Library0. By selecting "Build" for the Application project, the first time it should build all the referenced projects in order. But from now on, if no changes where made, pressing "Build" should not build anything, because MSBuild detects that changes where not made. A similar log output should be displayed:

========== Build: 0 succeeded, 0 failed, 3 up-to-date, 0 skipped ==========

But now, if changes where made, if you have the MSBuild log output level on "Diagnostic", the first line in the output window will display the reason of why does Visual Studio decides to build a project, like here:

Project 'Library0' is not up to date. Input file 'c:\Library0\Class1.cs' is modified after output file 'c:\Library0\bin\Debug\Library0.pdb'.

查看更多
倾城 Initia
5楼-- · 2019-01-26 05:38

The cause could be many things, so without having your solution + projects, we can only guess.

The typical way I handle this problem is by narrowing it down with a binary search. That is,

  1. I build everything.
  2. Next I find something in the middle of the build order and build that project. If something that that project depends on is the culprit, you'll experience the issue. If something that it doesn't depend on has the problem you won't (i.e. it will say all projects skipped).
  3. Now you repeat this process until you narrow it down to (hopefully) the project that has started causing the problem.

This (of course) only works if there is a single project that introduced the new problem (which is likely).

One of the culprits in my specific situation was having an x64 project reference an x86 project that wasn't selected to be built in the x64 configuration.

查看更多
Evening l夕情丶
6楼-- · 2019-01-26 05:44

I landed here looking for a solution to my own situation and none of the answers provided a fix.

After investigation I discovered a situation where UWP projects are compiled every time if the Copy to Output Directory property value is set to Copy always or Copy if newer on xaml files. In the past this would help solve certain compile issues, however since the introduction of xbf these values on these files force Visual Studio to recompile every time, even when there are no changes to any source code.

I wrote a blog post about it: Preventing Visual Studio Recompiles in UWP

I hope this helps someone.

查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-26 05:45

In my experience with this issue, it was only some of the projects that rebuilt, and the rebuilds failed several times before finally succeeding. It was apparently caused by the \rootprojectdir\.vs\%projectname%\v14\.suo file being corrupted. This also caused the same projects to require rebuilding, and the same windows to be opened every single time I opened VS. Deleting the .suo file (while VS was closed) and reopening VS fixed it :)

查看更多
登录 后发表回答