Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio (2012, 2015) rebuilds project although nothing has changed

I have a fairly large solution (approx. 50 projects, all C#) that I am building in VS 2012 (update 4). I noticed that after having done a complete rebuild from within VS, directly followed by a build (hitting F6) causes one project to rebuild, although I haven't touched anything.

A second invocation of build correctly detects that all projects are up to date.

Setting msbuild output to diagnostic and examining the output of the first build invocation shows this:

NuGet package restore started.
Restoring NuGet packages for solution XXX.
[... some boring lines on NuGet Package restore]
All packages are already installed and there is nothing to restore.
NuGet package restore finished.
Project 'YYY' is not up to date. Last build was with unsaved files.
------ Build started: Project: YYY, Configuration: Debug Any CPU ------
Build started 21-11-2013 21:20:54.

I am particularly intrigued by the message that Project 'YYY' is not up to date. Last build was with unsaved files. I have no unsaved files. Interestingly, both Google and Bing do not give a single hit when searching for this message.

Any clues on what could cause this? How could I debug this part of the build process? I believe that this part of the build process is even before the invocation of MsBuild (at least the new NuGet Package Restore functionality comes before MsBuild is invoked, I believe MsBuild kicks in from the 'Build started' line.

like image 531
Ralph Hendriks Avatar asked Nov 21 '13 20:11

Ralph Hendriks


Video Answer


2 Answers

This may be because your projects have circular references. To check this, set the MSBuild project build output verbosity to diagnostic.

Build your solution and search the build output pane for:

Done executing task "Copy"

Just above this line you will see lines like this:

Did not copy from file
Copying file from 

You will see lines like this:

3>  Copying file from "C:\Projects\test\Business.Core.Mto\bin\Debug\Business.Core.Mto.dll" to "bin\Debug\Business.Core.Mto.dll". (TaskId:68)

You can ignore the copying of non-dll files

Go to the original line containing the Done executing task "Copy" text.

You'll now see a line like this:

3>Done building target "_CopyFilesMarkedCopyLocal" in project "Business.Core.Utils.csproj".: (TargetId:138)

In Visual Studio, open the references within this project. Remove all references and add them back in. You may get a message:

A reference to business.core.mto could not be added. Adding this project as a reference would cause a circular dependency

The solution may now build.

It is likely that when moving projects around and refactoring, the reference may have been orphaned and is no longer necessary.

like image 123
Brian Leeming Avatar answered Oct 24 '22 23:10

Brian Leeming


OK, I finally could resolve this myself. I apparently overlooked one dependency that was not set as project dependency. This is necessary since not all projects in the solution are linked through project references but through ordinary binary references (since a subset of projects can also be opened in a partial solution where most of the development takes place, for faster loading etc.).

like image 22
Ralph Hendriks Avatar answered Oct 25 '22 01:10

Ralph Hendriks