visual-studio 为什么 Visual Studio 2008 总是重建我的整个项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1022485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:40:57  来源:igfitidea点击:

Why is Visual Studio 2008 always rebuilding my whole project?

visual-studiorebuild

提问by Rocketmagnet

I have a Visual Studio project with about 60 C++ source files. I can do a build, and it completes without errors. But if I immediately hit F7 again, it always re-compiles about 50 of the source files. It doesn't re-compile all of the files, which is strange.

我有一个包含大约 60 个 C++ 源文件的 Visual Studio 项目。我可以进行构建,并且它可以毫无错误地完成。但是如果我立即再次按下 F7,它总是会重新编译大约 50 个源文件。它不会重新编译所有文件,这很奇怪。

I have 'Enable minimal rebuild' (/Gm) set. Any ideas why it might be doing this? None of the files have a Modified Date in the future.

我设置了“启用最小重建”(/Gm)。任何想法为什么它可能会这样做?这些文件都没有未来的修改日期。

回答by Robert Harvey

Are any of your file dates in the future? This can occur if you changed time zones or changed the system clock time. Dates in the future will confuse the IDE and force a rebuild every time F7 or F5 is hit.

你的文件日期是将来的吗?如果您更改了时区或更改了系统时钟时间,就会发生这种情况。未来的日期会混淆 IDE 并在每次按下 F7 或 F5 时强制重建。

回答by Dimitry

I've solved the same problem.

我已经解决了同样的问题。

In my case compiler displayed warning, that /Zi option is required if /Gm is specified.

在我的情况下,编译器显示警告,如果指定了 /Gm,则需要 /Zi 选项。

/Gm enables "minimum rebuild", which requires debug information in .pdb file. So, if you don't want to use .pdb, also disable minumum rebuild - it solved a problem in my case.

/Gm 启用“最小重建”,这需要 .pdb 文件中的调试信息。因此,如果您不想使用 .pdb,也请禁用最小重建 - 在我的情况下它解决了一个问题。

回答by C?t?lin Piti?

Most probably is a matter of dependencies.

很可能是依赖关系的问题。

Consider the following possibilities:

考虑以下可能性:

  • If you have custom build tools defined for some of the files in your solution, make sure that the output property contains the right file name(s). If the output of the build tool doesn't correspond to the one(s) specified in the output file names, the builder will rebuild that file.

  • If you have custom build events, check whether the output from those build events don't affect the dependencies of the files to be built.

  • I had problems when trying, at post-build, to copy or move some of the output files to a build folder. The post build operations that affect the timestamp of the ouput files of the build process will determine rebuild each time.

  • 如果您为解决方案中的某些文件定义了自定义构建工具,请确保输出属性包含正确的文件名。如果构建工具的输出与输出文件名中指定的不对应,构建器将重建该文件。

  • 如果您有自定义构建事件,请检查这些构建事件的输出是否不会影响要构建的文件的依赖关系。

  • 在构建后尝试将某些输出文件复制或移动到构建文件夹时遇到问题。影响构建过程输出文件时间戳的构建后操作将决定每次重建。

回答by Oleg Akhrem

Project Properties -> "C/C++" -> "Output Files" -> "Program Database File Name" option should not be empty. Set this option by selecting from drop-down box . The option will be set like this: $(IntDir)\vc90.pdb. And line ProgramDataBaseFileName="" will be removed from vcproj file.

Project Properties -> "C/C++" -> "Output Files" -> "Program Database File Name" 选项不应为空。通过从下拉框中选择来设置此选项。该选项将设置为:$(IntDir)\vc90.pdb。并且行 ProgramDataBaseFileName="" 将从 vcproj 文件中删除。

Then only changed *.cpp files will be recompiled when you build the project or solution.

然后,当您构建项目或解决方案时,只会重新编译更改的 *.cpp 文件。

回答by Werner W.

In my case of such effect (C++ via VS2005) it was on Release configuration only, and the Studio tells in the build output, that compiler option /Gm is ignored if /Zi - option is not set. After setting /Zi via

在我的这种效果(通过 VS2005 的 C++)的情况下,它仅在发布配置上,并且 Studio 在构建输出中告诉,如果 /Zi - 选项未设置,编译器选项 /Gm 将被忽略。设置/Zi via后

Configuration Properties -> C/C++ -> General -> Debug Information Format : Program Database (/Zi) ,

Configuration Properties -> C/C++ -> General -> Debug Information Format : Program Database (/Zi) ,

it was ok. But isn`t there something wrong, when the Release Configuration needs something about Debugging? Not yet clear to me!

这个还行吧。但是,当发布配置需要调试时,是不是有什么问题?我还不清楚!

回答by Ravenous

After a couple days of googling, I ended up with a solution to my problem.

经过几天的谷歌搜索,我最终找到了解决我的问题的方法。

I encountered this problem when I moved my projects to a new PC. I had checked several times the creation date of the files. These dates were up-to-date, however the modification dates were in the bast (kinda bizarre) even when I changed the files.

当我将项目移动到新 PC 时,我遇到了这个问题。我已经多次检查文件的创建日期。这些日期是最新的,但是即使我更改了文件,修改日期也很糟糕(有点奇怪)。

A simple update of the files resolved the problem.

文件的简单更新解决了问题。

回答by Jamie Fristrom

I'm having the same problem, and it seems to be because I've turned browse information off. Properties->C/C++->Browse Info->Enable Browse Info->None. The only fix I've found is turning it back on. This is for an xbox 360 project, fwiw, my other projects don't have the problem.

我遇到了同样的问题,似乎是因为我关闭了浏览信息。属性->C/C++->浏览信息->启用浏览信息->无。我找到的唯一解决方法是重新打开它。这是一个 xbox 360 项目,fwiw,我的其他项目没有问题。

回答by Cameron

It seems that this problem can be caused by many things, but what fixed it for me was:

似乎这个问题可能是由很多事情引起的,但为我解决的是:

  1. Closing Visual Studio
  2. Manually deleting allbinand objfolders (Clean doesn't seem to do the trick)
  3. Opening the solution and running Clean (I'm not sure if this is necessary, but I did it just in case...)
  4. Building like normal
  1. 关闭 Visual Studio
  2. 手动删除所有binobj文件夹(Clean 似乎不起作用)
  3. 打开解决方案并运行 Clean(我不确定这是否有必要,但我这样做是为了以防万一......)
  4. 像往常一样建造

Note: This was for a C# program in Visual Studio 2010.

注意:这是针对 Visual Studio 2010 中的 C# 程序。

回答by ChrisW

A reason is if the 'date last modified' for one of the source file is set for some date in the future: it rebuilds, and then the source file is still later than the executable.

一个原因是如果源文件之一的“上次修改日期”设置为将来的某个日期:它会重建,然后源文件仍然晚于可执行文件。

This problem with the dates can happen if the source file is located in a directory a remote machine (a network share), and/or may even happen if your machine's time isn't synchronised with the date of the machine which is running the server of your source version control system.

如果源文件位于远程机器(网络共享)的目录中,则可能会发生日期问题,并且/或者如果您的机器时间与运行服务器的机器的日期不同步,甚至可能会发生日期问题源版本控制系统。

回答by Jeff

Check your project includes any .h header file that doesn't exist on disk. Always happens to me when I delete a header file I'm not actually including anywhere, but forget to delete it from my solution navigator in VS. Note: missing headers produce no errors during the build (when not #included anywhere).

检查您的项目是否包含磁盘上不存在的任何 .h 头文件。当我删除一个实际上没有包含在任何地方的头文件时,总是会发生在我身上,但忘记从 VS 中的解决方案导航器中删除它。注意:缺少的头文件在构建过程中不会产生错误(如果没有 #included 任何地方)。