Visual Studio C# projects force a rebuild when switching from debug to release and vice-versa

旧城冷巷雨未停 提交于 2019-12-07 01:24:35

问题


It seems Visual Studio 2012 C# projects force a rebuild every time you switch from Debug to Release or vice-versa, even if nothing has changed in the project. This does not happen for a standalone project -- but if you add a single project reference to a class library it starts exhibiting the behavior every time you change to a different build configuration. I've tracked it down to the generation of the force.build file (in obj\Debug or obj\Release) whenever the configuration selection changes. Why is this? Can it be disabled? I would think that switching configurations should not in and of itself require a rebuild. I cannot find any mention of the "force.build" file and/or how to disable this "feature" in any documentation.

To recreate the issue:

  1. Click File/New Project...
  2. Create a new Visual C# -> Console Application. Leave the generated code as-is.
  3. Right-click on the new solution in the solution explorer and select Add -> New Project...
  4. Choose Visual C# -> Class Library. Leave the generated code as-is.
  5. Right-click on the ConsoleApplication1 in the solution explorer and select Add Reference...
  6. Check the box next to ClassLibrary1 in Solution -> Projects and hit OK.
  7. Build the project in Debug configuration. It builds, as expected.
  8. Switch to Release configuration and build again. It builds, as expected.
  9. Switch back to Debug and build again. It builds, and it shouldn't. It's already been built, right? All we did was change the target configuration selection.

Is this a bug? Is there a workaround?


回答1:


I admit i've never paid much attention to it, but i tried just for curiosity (Visual Studio 2012 Update 4).

With a single project like you described, i tried switching configurations, and appearently, when i change the configuration, the main project builds again:

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

But if i look at the output folder, no file is being updated (the changed time of each file it's the same as the previous build), except for the vshost.exe (i disabled it, but got the same message). I tried then to set the build log to be more verbose (Tools - Options Projects and Solutions - build and Run - MSBuild project build output verbosity - Change from "Minimal" to "Normal" or "Detailed"):

Then i got the following output:

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 ==========

So it seems that the project doesn't really get rebuilded every time. If you find instead that everything gets rebuilded (check the changed time on output dir files), then try to increase the build log verbosity as i described and see what is happening. Hope it helps.



来源:https://stackoverflow.com/questions/32956136/visual-studio-c-sharp-projects-force-a-rebuild-when-switching-from-debug-to-rele

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!