Visual Studio C#项目在从调试切换到发布时强制重建,反之亦然
似乎Visual Studio 2012 C#项目每次从Debug切换到Release时都会强制重建,反之亦然,即使项目中没有任何更改也是如此。 对于独立项目,这不会发生 – 但如果您将一个项目引用添加到类库,则每次更改为不同的构建配置时,它都会开始显示该行为。 每当配置选择发生变化时,我都会跟踪它生成force.build
文件(在obj\Debug
或obj\Release
)。 为什么是这样? 可以禁用吗? 我认为切换配置本身不应该需要重建。 我找不到任何提及“force.build”文件和/或如何在任何文档中禁用此“function”。
要重新创建问题:
- 单击
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 ==========
因此,似乎每次都没有真正重建项目。 如果您发现所有内容都被重建(检查输出目录文件上的更改时间),那么尝试按照我的描述增加构建日志详细程度,看看发生了什么。 希望能帮助到你。