【问题标题】:Visual Studio always re-compiles code even if it hadn't changedVisual Studio 总是重新编译代码,即使它没有改变
【发布时间】:2014-01-28 04:02:54
【问题描述】:

对我的项目进行一些更改后,Visual Studio 开始总是重新编译所有源代码,导致所有依赖项目也重新编译,大大减慢了开发速度。这是为什么呢?

  • 仅在选中XML documentation file 并且存在带有Copy always 的文件时才会发生。如果您更改其中任何一个,则不会重新编译源代码。
  • 仅在 Visual Studio 中编译时发生 - 从命令行使用 MSBuild 编译时,不会重新编译源代码。
  • Visual Studio 2012 更新 4。

【问题讨论】:

  • 我使用 VS 2013 Update 2 并且看到了相同的不良行为:源代码未发生更改时重新编译项目。即使我没有在我的解决方案的任何项目中检查“XML 文档文件”,它也会发生。所以还有其他原因。 :-(
  • 好吧,您可以按照我下面的回答中的描述进行调查,然后报告您的发现。

标签: visual-studio visual-studio-2012 incremental-build


【解决方案1】:

这似乎是 Visual Studio 中的一个错误,当项目有 XML documentation file 检查带有 Copy always 的一些文件时。

复制:

  1. 创建新项目 - C# 类库。
  2. 项目属性 => 构建 => 检查XML documentation file
  3. 项目 => 添加 => 新项目 => 文本文件 TextFile1.txt
  4. 将 TextFile1.txt Copy to Output Directory 更改为 Copy always
  5. 右键单击项目 => 构建
    • 项目编译
  6. 右键单击项目 => 构建

预期:不应构建项目,构建输出应显示:

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

实际:项目正在构建,输出为:

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

调查:打开详细日志,您会看到:

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.

查看 procmon,您会看到 devenv.exe 在 MSBuild.exe 运行之前将“ClassLibrary1.XML”重命名为“vsA381.tmp”。重命名的堆栈跟踪:

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

【讨论】:

    猜你喜欢
    • 2019-09-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2019-09-25
    • 2019-06-13
    • 2014-09-13
    • 2014-12-10
    • 1970-01-01
    相关资源
    最近更新 更多