Jonathan
Jonathan

Reputation: 7551

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

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?

Upvotes: 3

Views: 2312

Answers (1)

Jonathan
Jonathan

Reputation: 7551

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

Upvotes: 2

Related Questions