C++ 解决 Visual Studio 2010 AlwaysCreate 重建问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4185638/
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
Solving the Visual Studio 2010 AlwaysCreate rebuild issue
提问by SmacL
I've a C++ project that I'm currently porting from VS2008 to VS2010. When I build the project, Visual Studio 2010 reports the build as successful but if I then press F5 to start the debugger I'm told that the project is not up to date. If I ignore this warning, I can continue debugging ok, but if I press ok, the whole project (many hundreds of source files), gets rebuilt from scratch. The output contains the following;
我有一个 C++ 项目,目前正在从 VS2008 移植到 VS2010。当我构建项目时,Visual Studio 2010 报告构建成功,但如果我按 F5 启动调试器,我会被告知该项目不是最新的。如果我忽略这个警告,我可以继续调试,但是如果我按确定,整个项目(数百个源文件)将从头开始重建。输出包含以下内容;
1>------ Build started: Project: SCCW-VC2010, Configuration: Debug Win32 ------
1>Build started 15/11/2010 14:47:40.
1>InitializeBuildStatus:
1> Creating "Debug\SCCW-VC2010.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>Midl:
1> All outputs are up-to-date.
1>ClCompile:
1> tinedit.cpp
1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1> Automatically linking with sfl504d.lib
1> Automatically linking with ot1104d.lib
1>c:\program files\rogue wave\stingray studio 10.4\include\toolkit\sectndlg.h(134): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1> Automatically linking with og1204d.lib
1> Automatically linking with RWUXThemeD10.lib
1> profile.cpp
1> ZOffsetDialog.cpp
Half an hour later, once the build is finished, the debugger starts. My guess is that the message
半小时后,一旦构建完成,调试器就会启动。我的猜测是消息
Creating "Debug\SCCW-VC2010.unsuccessfulbuild" because "AlwaysCreate" was specified.
由于指定了“AlwaysCreate”,因此正在创建“Debug\SCCW-VC2010.unsuccessfulbuild”。
is part of the problem, but I cant tie this to a project setting. I've found some help on google, but nothing that has worked thus far. Anyone else had this problem and know of a fix?
是问题的一部分,但我无法将其与项目设置联系起来。我在 google 上找到了一些帮助,但到目前为止没有任何效果。其他人有这个问题并知道修复吗?
Edit:As per Jalf's suggestion in the comments below, I have created a new projected, imported all my files into that project, and the new project has the same problems. Specifically, I copied over all the following groups;
编辑:根据 Jalf 在下面评论中的建议,我创建了一个新项目,将我的所有文件导入到该项目中,并且新项目存在相同的问题。具体来说,我复制了以下所有组;
<ClCompile Include="..\MyDir\MyFile.cpp"/>
<ClInclude Include="..\MyDir\MyFile.h" />
<None Include="res\MyFile.ico" /> (and all similar resources)
<Library Include="..\MyDir\MyFile.lib" />
Edit2:After going through all the header includes I eventually found 3 that did not exist. Removing them and doing a rebuild all on the original project seems to have fixed the problem. Some of the blog posts that mention this problem refer to it as a bug, and two days of lost time later, I tend to agree. Thanks for the answers and comments provided.
Edit2:在浏览完所有标题后,我最终发现了 3 个不存在的。删除它们并在原始项目上进行所有重建似乎已经解决了问题。一些提到这个问题的博客文章将其称为一个错误,两天后的损失时间,我倾向于同意。感谢您提供的答案和评论。
Edit3:And one day later the problem is back! Making any edit to any file in the project once again causes a full rebuild. As per John Dibling's answer, the project does include some static libraries, including Stingray. I'm ditching VS2010 and moving back to VS2008, as I have deadlines. For related information, see the following links;
Edit3:一天后问题又回来了!对项目中的任何文件进行任何编辑都会再次导致完全重建。根据 John Dibling 的回答,该项目确实包含一些静态库,包括 Stingray。我正在放弃 VS2010 并回到 VS2008,因为我有截止日期。有关相关信息,请参阅以下链接;
VS2010 always thinks project is out of date but nothing has changed
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/38c08137-3bb0-4143-b97f-72d077646318
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/38c08137-3bb0-4143-b97f-72d077646318
http://blogs.msdn.com/b/vsproject/archive/2009/07/21/enable-c-project-system-logging.aspx
http://blogs.msdn.com/b/vsproject/archive/2009/07/21/enable-c-project-system-logging.aspx
Final EditThe release of VS2010 SP1 has solved this problem, and builds are now fast and efficient.
最终编辑VS2010 SP1 的发布已经解决了这个问题,并且构建现在快速高效。
采纳答案by John Dibling
I've had this problem many times and it was always frustrating. I'll tell you what the problem was in my case, but first I have to ask you:
我已经多次遇到这个问题,而且总是令人沮丧。我会告诉你我的问题是什么,但首先我必须问你:
- Did you do a rebuild-all before you tried running the first time, or just a rebuild?
- Once you do a rebuild all, does it ask you yet again to rebuild if you've made no changes?
- 在第一次尝试运行之前,您是否进行了全部重建,或者只是重建?
- 一旦你全部重建,如果你没有做任何改变,它会再次要求你重建吗?
The problem in my case was somewhat complex. I had custom build rules that copies binaries for Stingray from their source directory (where they lived) to a directory in my build tree. The binaries were marked as a dependancy, so that they were copied before each build in case they changed.
我的问题有点复杂。我有自定义构建规则,可以将 Stingray 的二进制文件从它们的源目录(它们所在的位置)复制到我的构建树中的一个目录中。二进制文件被标记为依赖项,以便在每次构建之前复制它们,以防它们发生变化。
The dependancy checked looked at the timestamps of these files to see when they were changed. If the blah.lib
had a mod date of last December in it's source directory, then when it was copied it would have the same mod date. The dependancy checked would note that "hey this file's pretty old, we have to rebuild it," and then it would ask if I wanted to do a full rebuild.
检查的依赖性查看这些文件的时间戳以查看它们何时被更改。如果blah.lib
它的源目录中有去年 12 月的 mod 日期,那么当它被复制时,它将具有相同的 mod 日期。检查的依赖性会指出“嘿,这个文件很旧,我们必须重建它”,然后它会询问我是否要进行完全重建。
For a while I got by by just saying "No," but eventually I fixed the problem by changing the custom build rule to write a new text file after it did the file copy. That would make the new text file the dependancy, and not the blah.lib
file, and it made the compiler happy.
有一段时间我只是说“不”,但最终我通过更改自定义构建规则以在完成文件复制后编写新的文本文件来解决问题。这将使新文本文件成为依赖项,而不是blah.lib
文件,这让编译器感到高兴。
回答by xen
See in output window what file is rebuild
Go to menu
Tools
->Options
, then navigate toProject and Solutions
->Build and Run
. Change optionMSBuild Project build output verbosity
to:Diagnostic
Build, got long log
Find file (from 1) in log, read diagnostic. You may found for example header name which has date in future or absent.
在输出窗口中查看正在重建的文件
转到菜单
Tools
->Options
,然后导航到Project and Solutions
->Build and Run
。将选项更改MSBuild Project build output verbosity
为:Diagnostic
构建,有很长的日志
在日志中查找文件(从 1 开始),读取诊断信息。例如,您可能会发现包含未来日期或不存在日期的标题名称。
回答by GTAE86
I had the same problem on both converted and from-scratch projects. I got a hint from a MS page about missing files. I checked my project and found that it referenced a file that did not exist. Replaced it with the correct file, and the problem went away.
我在转换项目和从头开始的项目上都遇到了同样的问题。我从 MS 页面得到了一个关于丢失文件的提示。我检查了我的项目,发现它引用了一个不存在的文件。用正确的文件替换它,问题就消失了。
回答by JohnCz
I know this is a very, very old post but for the benefit of all who still have this problem I decided to post my input. because "AlwaysCreate" was specified has nothing to do with project being rebuilt.
我知道这是一个非常非常古老的帖子,但为了所有仍然有这个问题的人的利益,我决定发布我的意见。因为指定了“AlwaysCreate”与正在重建的项目无关。
IT is the other way around. If you or Visual Studio decides to rebuild all, this causes creation of the "*.unsuccessfulbuild" file.
IT 则相反。如果您或 Visual Studio 决定全部重建,则会导致创建“*.unsuccessfulbuild”文件。
Some other issue (usually header that does not exist) will cause rebuild all leading to displaying because "AlwaysCreate" was specified.
其他一些问题(通常是不存在的标题)将导致重建所有导致显示,因为指定了“AlwaysCreate”。
"AlwaysCreate" is a part of Visual Studio build environment settings and is part of the Microsoft.CppBuild.targets XML file. It contains following line: Touch AlwaysCreate="true" Files="$(LastBuildUnsuccessful)"/
“AlwaysCreate”是 Visual Studio 生成环境设置的一部分,也是 Microsoft.CppBuild.targets XML 文件的一部分。它包含以下行:Touch AlwaysCreate="true" Files="$(LastBuildUnsuccessful)"/
It this is set to true, ".unsuccessfulbuild" file will always be created regardless of the build being successful or not. If this is changed to false, ".unsuccessfulbuild is not created. If true the *.unsuccessfulbuild file is created as empty for the duration of the build process and then delete if build is successful. I am not sure why this file is created; even if the build has errors, the file is empty but not deleted as in case of the successful build.
如果设置为 true,无论构建是否成功,“. unsuccessfulbuild”文件都会被创建。如果将其更改为 false,则不会创建 .unsuccessfulbuild。如果为 true,则在构建过程中将 *.unsuccessfulbuild 文件创建为空文件,如果构建成功则将其删除。我不确定为什么创建此文件;即使构建有错误,文件也是空的,但不会像构建成功那样被删除。
Possibly the existence of this file has some meaning known only to VS build environment. If you want to play with this setting, deleting Touch key from
可能这个文件的存在有一些只有 VS 构建环境才知道的意义。如果你想玩这个设置,从
回答by Steve Townsend
回答by Kari
In my case it seemed to help to build the deployment project(s). I have set them not to build when I hit F7but manually. Some people suggest creating a new solution + projects but that's not a very good option when the projects have a lot of manual tweaking and custom build rules.
就我而言,它似乎有助于构建部署项目。我已经将它们设置为在我点击时不构建F7而是手动构建。有些人建议创建一个新的解决方案 + 项目,但当项目有很多手动调整和自定义构建规则时,这不是一个很好的选择。
回答by SmacL
Decided to revisit this with the release version of SP1. I recreated a new project from scratch, which came out at 81k compared to the upgraded older project of 1.4mb which was carrying all sorts of junk with it. Initially, I came across the same problem, but managed to resolve it as follows;
决定在 SP1 的发行版中重新审视这一点。我从头开始重新创建了一个新项目,与升级后的 1.4mb 旧项目相比,它的大小为 81k,后者带有各种垃圾。最初,我遇到了同样的问题,但设法解决了以下问题;
- Changed pre-compiled headers to Create (/Yc)
- Compiled one source file
- Changed pre-compiled headers to Use (/Yu)
- Did a full rebuild
- 将预编译头文件更改为Create (/Yc)
- 编译一个源文件
- 将预编译头文件更改为Use (/Yu)
- 进行了全面重建
Next problem I noticed was that any resource addition was causing a recompile of all files containing including resource.h This was fixed using advice from the following Microsoft connect threadand manually adding the following lines to my project;
我注意到的下一个问题是,任何资源添加都会导致重新编译包含 resource.h 的所有文件,这是使用来自以下Microsoft 连接线程的建议并手动将以下几行添加到我的项目中修复的;
<ItemGroup>
<ClNoDependencies Include="Resource.h" />
</ItemGroup>
回答by Devolus
The link is in one of the comments here, but it is easy to miss, so I repost the basic steps here from this link: MSDN Article
该链接位于此处的评论之一中,但很容易错过,因此我从该链接重新发布了基本步骤:MSDN 文章
Actually I found this link on my own, and only later realized that this was already mentioned here.
其实我自己找到了这个链接,后来才意识到这里已经提到了。
1. Since it can be difficult to recover from a damaged devenv.exe.config file, consider copying the file to devenv.exe.config.original before modifying it so you have a backup copy you can revert to if things go awry.
2. Open your VisualStudioInstallFolder\Common7\IDE\devenv.exe.config file. Note this will be in %ProgramFiles(x86)% on 64-bit Windows.
3. Open a text editor with admin privileges.
4. Add this snippet to your devenv.exe.config file just below the <configSections /> block:
For Visual Studio 2012 and below...
<system.diagnostics>
<switches><add name="CPS" value="4" /></switches>
</system.diagnostics>
For Visual Studio 2013
<system.diagnostics>
<switches><add name="CPS" value="Verbose" /></switches>
</system.diagnostics>
5. Save the text file.
I use Visual Studio 2010 + SP1 and both of the XML snippets seem to work.
我使用 Visual Studio 2010 + SP1,两个 XML 片段似乎都可以工作。
Now you need a tool that can display windows DebugOutput like DebugView.
现在您需要一个可以像DebugView一样显示 windows DebugOutput 的工具。
1. Start DebugView
2. Rebuild
3. Build
4. In DebugView window search for the string ‘missing' or 'not up to date', better still to save the DebugView log entries and open it in notepad and then search.
回答by ulatekh
If there are no "legitimate" reasons for the constant rebuilding (e.g. references to missing header files), try deleting the solution's .sdf
file (when the solution is closed, of course) and rebuilding. That just worked for me.
如果不断重建没有“合法”的原因(例如引用丢失的头文件),请尝试删除解决方案的.sdf
文件(当然,当解决方案关闭时)并重建。这对我有用。
回答by Camille Morin
Solution modifying devenv.exe.config + use of DebugViewworked for me (vs2010).
修改 devenv.exe.config + 使用 DebugView 的解决方案对我有用(vs2010)。
DebugViewlists the missing file for you.
DebugView 会为您列出丢失的文件。