Visual Studio always re-compiles code even if it hadn't changed

2k views Asked by At

After some changes to my project, Visual Studio started to always re-compiles all sources, causing all dependent project to also re-compile, slowing down development considerably. Why is that?

  • Happens only when XML documentation file is checked and there's some file with Copy always. If you change either of these, the sources don't get re-compiled.
  • Happens only when compiling inside Visual Studio - when compiling using MSBuild from commandline, the sources don't get re-compiled.
  • Visual Studio 2012 Update 4.
1

There are 1 answers

0
Jonathan On

This appears to be a bug in Visual Studio, when project has XML documentation file checked some files with Copy always.

Repro:

  1. Create new project - C# class library.
  2. Project Properties => Build => check XML documentation file
  3. Project => Add => New Item => Text file TextFile1.txt
  4. Change TextFile1.txt Copy to Output Directory to Copy always
  5. Right-click project => build
    • project compiles
  6. Right-click project => build

Expected: Project shouldn't be built, build output should say:

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

Actual: Project is build, output is:

------ Build started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
  ClassLibrary1 -> bin\Debug\ClassLibrary1.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Intestigation: Turning on detailed log, you see:

Target "CoreCompile" in file "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets" from project "ClassLibrary1.csproj" (target "Compile" depends on it):
Building target "CoreCompile" completely.
Output file "bin\Debug\ClassLibrary1.XML" does not exist.

Looking in procmon, you see that devenv.exe renames "ClassLibrary1.XML" into "vsA381.tmp" just before MSBuild.exe runs. Stack trace for the rename:

KERNEL32!MoveFileW+0x17
csproj!CMoveOutOfTheWayScope::EnterScope+0x85
csproj!CVsProjBuildableProjectCfg::StartBuildProcessWithTarget+0x50b
csproj!CVsProjBuildableProjectCfg::StartBuildProcess+0xc
csproj!CVsProjBuildableProjectCfg::StartBuildEx+0x15
msenv!CSUIBuilder::DoBuild+0x1a3
msenv!CSUIBuilder::Run+0x66