似乎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...
ClassLibrary1
中的Solution
旁边的框 - > Projects
并点击OK
。Debug
配置构建项目。正如预期的那样构建它。Release
配置并重新构建。正如预期的那样构建它。Debug
并重新构建。它构建,它不应该。它已经建好了,对吗?我们所做的就是更改目标配置选择。这是一个错误吗?有解决方法吗?
答案 0 :(得分:2)
我承认我从来没有过多关注它,但我只是为了好奇而尝试(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 ==========
所以看起来这个项目并没有真正得到每次重建。如果您发现所有内容都被重建(检查输出目录文件上的更改时间),那么尝试按照我的描述增加构建日志详细程度,看看发生了什么。希望它有所帮助。
答案 1 :(得分:0)
这确实似乎是一个错误(VS 2017 和 VS 2019):
https://developercommunity.visualstudio.com/t/changing-solution-configuration-rebuilds-dependent/726161
切换配置(build.force
/obj
或 x86
/x64
)时会在 Debug
文件夹中创建一个文件 Release
。这个文件的创建是错误的。上面的链接描述了问题和 Microsoft 的响应(“不会修复,请移至 .Net Core”)。