![](/img/trans.png)
[英]Visual Studio Rebuilds projects when switching from debug to release and vice-versa when option XML documentation is selected
[英]Visual Studio C# projects force a rebuild when switching from debug to release and vice-versa
似乎 Visual Studio 2012 C# 项目每次从 Debug 切换到 Release 时都会强制重建,反之亦然,即使项目中没有任何更改。 对于独立项目不会发生这种情况——但是如果您向类库添加单个项目引用,则每次更改为不同的构建配置时,它都会开始表现出这种行为。 每当配置选择发生变化时,我都会追踪到force.build
文件(在obj\\Debug
或obj\\Release
)的生成。 为什么是这样? 可以禁用吗? 我认为切换配置本身不应该需要重建。 我在任何文档中都找不到“force.build”文件和/或如何禁用此“功能”的任何提及。
要重新创建问题:
File
/ New Project...
Visual C#
-> Console Application
。 将生成的代码保留原样。Add
-> New Project...
Visual C#
-> Class Library
。 将生成的代码保留原样。ConsoleApplication1
并选择Add Reference...
Solution
-> Projects
ClassLibrary1
旁边的框,然后点击OK
。Debug
配置中构建项目。 它按预期构建。Release
配置并再次构建。 它按预期构建。Debug
并再次构建。 它构建,它不应该。 已经建好了是吧? 我们所做的只是更改目标配置选择。这是一个错误吗? 有解决方法吗?
我承认我从来没有过多关注它,但我只是出于好奇而尝试(Visual Studio 2012 Update 4)。
使用您描述的单个项目,我尝试切换配置,显然,当我更改配置时,主项目再次构建:
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
但是,如果我查看输出文件夹,除了 vshost.exe(我禁用了它,但得到了相同的消息)之外,没有文件正在更新(每个文件的更改时间与之前的版本相同)。 然后我尝试将构建日志设置为更详细(工具 - 选项项目和解决方案 - 构建和运行 - MSBuild 项目构建输出详细程度 - 从“最小”更改为“正常”或“详细”):
然后我得到以下输出:
1>------ Build started: Project: ConsoleApplication1, Configuration: Release Any CPU ------
1>Build started 06/10/2015 00:26:50.
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>CoreCompile:
1>Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
1>_CopyAppConfigFile:
1>Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
1>CopyFilesToOutputDirectory:
1> ConsoleApplication1 -> c:\users\user\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\bin\Release\ConsoleApplication1.exe
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.09
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
因此,该项目似乎并没有每次都真正重建。 如果您发现所有内容都被重建(检查输出目录文件上的更改时间),那么尝试按照我的描述增加构建日志的详细程度,看看发生了什么。 希望能帮助到你。
这确实似乎是一个错误(VS 2017 和 VS 2019):
https://developercommunity.visualstudio.com/t/changed-solution-configuration-rebuilds-dependent/726161
切换配置( x86
/ x64
或Debug
/ Release
)时会在obj
文件夹中创建一个文件build.force
。 这个文件的创建是错误的。 上面的链接描述了 Microsoft 的问题和响应( “不会修复,请移至 .Net Core” )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.