visual-studio Visual Studio 2010 总是认为项目已过时,但没有任何变化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2762930/
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 11:55:02  来源:igfitidea点击:

Visual Studio 2010 always thinks project is out of date, but nothing has changed

visual-studiovisual-studio-2010

提问by Chris U

I have a very similar problem as described here.

我有一个与此处描述的非常相似的问题。

I also upgraded a mixed solution of C++/CLI and C# projects from Visual Studio 2008 to Visual Studio 2010. And now in Visual Studio 2010 one C++/CLI project always runs out of date.

我还将 C++/CLI 和 C# 项目的混合解决方案从 Visual Studio 2008 升级到 Visual Studio 2010。现在在 Visual Studio 2010 中,一个 C++/CLI 项目总是过时。

Even if it has been compiled and linked just before and F5is hit, the messagebox "The project is out of date. Would you like to build it?" appears. This is very annoying because the DLL file is very low-tiered and forces almost all projects of the solution to rebuild.

即使它刚刚被编译和链接F5并被命中,消息框“该项目已过期。您要构建它吗?” 出现。这很烦人,因为 DLL 文件的层级非常低,并且强制重建解决方案的几乎所有项目。

My pdb settings are set to the default value (suggested solution of this problem).

我的 pdb 设置设置为默认值(此问题的建议解决方案)。

Is it possible the get the reason why Visual Studio 2010 forces a rebuild or thinks a project is up to date?

是否有可能获得 Visual Studio 2010 强制重建或认为项目是最新的原因?

Any other ideas why Visual Studio 2010 behaves like that?

为什么 Visual Studio 2010 的行为如此?

回答by Mosc

For Visual Studio/Express 2010 only. See other (easier) answers for VS2012, VS2013, etc

仅适用于 Visual Studio/Express 2010。查看 VS2012、VS2013 等的其他(更简单的)答案

To find the missing file(s), use info from the article Enable C++ project system loggingto enable debug logging in Visual Studio and let it just tell youwhat's causing the rebuild:

要查找丢失的文件,请使用文章启用 C++ 项目系统日志记录中的信息来启用 Visual Studio 中的调试日志记录,并让它告诉您导致重建的原因:

  1. Open the devenv.exe.configfile (found in %ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\or in %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\). For Express versions the config file is named V*Express.exe.config.
  2. Add the following after the </configSections>line:

    <system.diagnostics>
      <switches>
        <add name="CPS" value="4" />
      </switches>
    </system.diagnostics>
    
  3. Restart Visual Studio
  4. Open up DbgViewand make sure it's capturing debug output
  5. Try to debug (hit F5 in Visual Studio)
  6. Search the debug log for any lines of the form:

    devenv.exe Information: 0 : Project 'Bla\Bla\Dummy.vcxproj' not up to date because build input 'Bla\Bla\SomeFile.h' is missing.

    (I just hit Ctrl+F and searched for not up to date) These will be the references causing the project to be perpetually "out of date".

  1. 打开devenv.exe.config文件(在%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\或 中找到%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\)。对于 Express 版本,配置文件名为V*Express.exe.config.
  2. 在该</configSections>行之后添加以下内容:

    <system.diagnostics>
      <switches>
        <add name="CPS" value="4" />
      </switches>
    </system.diagnostics>
    
  3. 重新启动 Visual Studio
  4. 打开DbgView并确保它捕获调试输出
  5. 尝试调试(在 Visual Studio 中按 F5)
  6. 在调试日志中搜索以下形式的任何行:

    devenv.exe 信息:0:项目“Bla\Bla\Dummy.vcxproj”不是最新的,因为缺少构建输入“Bla\Bla\SomeFile.h”。

    (我只是按 Ctrl+F 并搜索not up to date)这些将是导致项目永久“过时”的引用。

To correct this, either remove any references to the missing files from your project, or update the references to indicate their actual locations.

要更正此问题,请从项目中删除对丢失文件的任何引用,或更新引用以指示其实际位置。

Note: If using 2012 or later then the snippet should be:

注意:如果使用 2012 或更高版本,则代码段应为:

<system.diagnostics>
  <switches>
   <add name="CPS" value="Verbose" />
  </switches>
</system.diagnostics>

回答by Stanislav

In Visual Studio 2012 I was able to achieve the same result easier than in the accepted solution.

在 Visual Studio 2012 中,我能够比接受的解决方案更容易获得相同的结果。

I changed the option in menu ToolsOptionsProjects and SolutionsBuild and Run→ *MSBuild project build output verbosity" from Minimalto Diagnostic.

我将菜单ToolsOptionsProjects and SolutionsBuild and Run→ *MSBuild project build output verbosity" 中的选项从Minimal更改为Diagnostic

Then in the build output I found the same lines by searching for "not up to date":

然后在构建输出中,我通过搜索“not up to date”找到了相同的行:

Project 'blabla' is not up to date. Project item 'c:\foo\bar.xml' has 'Copy to Output Directory' attribute set to 'Copy always'.

'blabla' 项目不是最新的。项目项“c:\foo\bar.xml”的“复制到输出目录”属性设置为“始终复制”。

回答by Dave

This happened to me today. I was able to track down the cause: The project included a header file which no longer existed on disk.

这件事今天发生在我身上。我能够找到原因:该项目包含一个不再存在于磁盘上的头文件。

Removing the file from the project solved the problem.

从项目中删除文件解决了问题。

回答by Zach

We also ran into this issue and found out how to resolve it.

我们也遇到了这个问题并找到了解决方法。

The issue was as stated above "The file no longer exists on the disk."

问题如上所述“该文件不再存在于磁盘上。”

This is not quite correct. The file does exist on the disk, but the .VCPROJ file is referencing the file somewhere else.

这并不完全正确。该文件确实存在于磁盘上,但 .VCPROJ 文件正在其他地方引用该文件。

You can 'discover' this by going to the "include file view" and clicking on each include file in turn until you find the one that Visual Studio can not find. You then ADD that file (as an existing item) and delete the reference that can not be found and everything is OK.

您可以通过转到“包含文件视图”并依次单击每个包含文件来“发现”这一点,直到找到 Visual Studio 找不到的那个。然后添加该文件(作为现有项目)并删除无法找到的引用,一切正常。

A valid question is: How can Visual Studio even build if it does not know where the include files are?

一个有效的问题是:如果 Visual Studio 不知道包含文件的位置,它如何构建?

We think the .vcproj file has some relative path to the offending file somewhere that it does not show in the Visual Studio GUI, and this accounts for why the project will actually build even though the tree-view of the includes is incorrect.

我们认为 .vcproj 文件有一些指向违规文件的相对路径,它没有显示在 Visual Studio GUI 中,这解释了为什么即使包含的树视图不正确,项目也会实际构建。

回答by Neverender

The accepted answer helped me on the right path to figuring out how to solve this problem for the screwed up project I had to start working with. However, I had to deal with a very large number of bad include headers. With the verbose debug output, removing one caused the IDE to freeze for 30 seconds while outputting debug spew, which made the process go very slowly.

接受的答案帮助我走上了正确的道路,为我必须开始工作的搞砸了的项目找出如何解决这个问题。但是,我不得不处理大量不良的包含标头。对于详细的调试输出,删除一个会导致 IDE 冻结 30 秒,同时输出 debug spew,这使得过程变得非常缓慢。

I got impatient and wrote a quick-and-dirty Python script to check the (Visual Studio 2010) project files for me and output all the missing files at once, along with the filters they're located in. You can find it as a Gist here: https://gist.github.com/antiuniverse/3825678(or this fork that supports relative paths)

我不耐烦了,写了一个又快又脏的 Python 脚本来检查 (Visual Studio 2010) 项目文件并一次输出所有丢失的文件,以及它们所在的过滤器。你可以找到它作为要点在这里:https: //gist.github.com/antiuniverse/3825678(或支持相对路径的这个分支

Example:

例子:

D:\...> check_inc.py sdk/src/game/client/swarm_sdk_client.vcxproj
[Header Files]:
  fx_cs_blood.h   (cstrike\fx_cs_blood.h)
  hud_radar.h   (cstrike\hud_radar.h)
[Game Shared Header Files]:
  basecsgrenade_projectile.h   (..\shared\cstrike\basecsgrenade_projectile.h)
  fx_cs_shared.h   (..\shared\cstrike\fx_cs_shared.h)
  weapon_flashbang.h   (..\shared\cstrike\weapon_flashbang.h)
  weapon_hegrenade.h   (..\shared\cstrike\weapon_hegrenade.h)
  weapon_ifmsteadycam.h   (..\shared\weapon_ifmsteadycam.h)
[Source Files\Swarm\GameUI - Embedded\Base GameUI\Headers]:
  basepaenl.h   (swarm\gameui\basepaenl.h)
  ...

Source code:

源代码:

#!/c/Python32/python.exe
import sys
import os
import os.path
import xml.etree.ElementTree as ET

ns = '{http://schemas.microsoft.com/developer/msbuild/2003}'

#Works with relative path also
projectFileName = sys.argv[1]

if not os.path.isabs(projectFileName):
   projectFileName = os.path.join(os.getcwd(), projectFileName)

filterTree = ET.parse(projectFileName+".filters")
filterRoot = filterTree.getroot()
filterDict = dict()
missingDict = dict()

for inc in filterRoot.iter(ns+'ClInclude'):
    incFileRel = inc.get('Include')
    incFilter = inc.find(ns+'Filter')
    if incFileRel != None and incFilter != None:
        filterDict[incFileRel] = incFilter.text
        if incFilter.text not in missingDict:
            missingDict[incFilter.text] = []

projTree = ET.parse(projectFileName)
projRoot = projTree.getroot()

for inc in projRoot.iter(ns+'ClInclude'):
    incFileRel = inc.get('Include')
    if incFileRel != None:
        incFile = os.path.abspath(os.path.join(os.path.dirname(projectFileName), incFileRel))
        if not os.path.exists(incFile):
            missingDict[filterDict[incFileRel]].append(incFileRel)

for (missingGroup, missingList) in missingDict.items():
    if len(missingList) > 0:
        print("["+missingGroup+"]:")
        for missing in missingList:
            print("  " + os.path.basename(missing) + "   (" + missing + ")")

回答by Alexandre Pelletier

I've deleted a cpp and some header files from the solution (and from the disk) but still had the problem.

我已经从解决方案(和磁盘)中删除了一个 cpp 和一些头文件,但仍然有问题。

Thing is, every file the compiler uses goes in a *.tlog file in your temp directory. When you remove a file, this *.tlog file is not updated. That's the file used by incremental builds to check if your project is up to date.

事实是,编译器使用的每个文件都在临时目录中的 *.tlog 文件中。删除文件时,此 *.tlog 文件不会更新。这是增量构建用来检查您的项目是否是最新的文件。

Either edit this .tlog file manually or clean your project and rebuild.

手动编辑此 .tlog 文件或清理您的项目并重建。

回答by JJTh

I had a similar problem, but in my case there were no files missing, there was an error in how the pdb output file was defined: I forgot the suffix .pdb (I found out with the debug logging trick).

我遇到了类似的问题,但在我的情况下,没有文件丢失,pdb 输出文件的定义方式存在错误:我忘记了后缀 .pdb(我是通过调试日志记录技巧发现的)。

To solve the problem I changed, in the vxproj file, the following line:

为了解决我改的问题,在vxproj文件中,下面一行:

<ProgramDataBaseFileName>MyName</ProgramDataBaseFileName>

to

<ProgramDataBaseFileName>MyName.pdb</ProgramDataBaseFileName>

回答by Bim

I had this problem in VS2013 (Update 5) and there can be two reasons for that, both of which you can find by enabling "Detailed" build output under "Tools"->"Projects and Solutions"->"Build and Run".

我在 VS2013(更新 5)中遇到了这个问题,可能有两个原因,您可以通过在“工具”->“项目和解决方案”->“构建和运行”下启用“详细”构建输出来找到这两个原因.

  1. "Forcing recompile of all source files due to missing PDB "..."
    This happens when you disable debug information output in your compiler options (Under Project settings: ?C/C++“->“Debug Information Format“ to ?None“ and ?Linker“->“Generate Debug Info“ to ?No“: ). If you have left ?C/C++“->“Program Database File Name“ at the default (which is ?$(IntDir)vc$(PlatformToolsetVersion).pdb“), VS will not find the file due to a bug (https://connect.microsoft.com/VisualStudio/feedback/details/833494/project-with-debug-information-disabled-always-rebuilds).
    To fix it, simply clear the file name to "" (empty field).

  2. "Forcing rebuild of all source files due to a change in the command line since the last build."
    This seems to be a known VS bug too (https://connect.microsoft.com/VisualStudio/feedback/details/833943/forcing-rebuild-of-all-source-files-due-to-a-change-in-the-command-line-since-the-last-build) and seems to be fixed in newer versions (but not VS2013). I known of no workaround, but if you do, by all means, post it here.

  1. "Forcing recompile of all source files due to missing PDB "..."
    当您在编译器选项中禁用调试信息输出时会发生这种情况(在项目设置下:?C/C++“->“Debug Information Format“ to ?None” 和 ?Linker“->“Generate Debug Info“ to ?No“: ) . 如果你把?C/C++”->“Program Database File Name”保留为默认值(即?$(IntDir)vc$(PlatformToolsetVersion).pdb“),VS将不会因为一个bug而找不到该文件( https ://connect.microsoft.com/VisualStudio/feedback/details/833494/project-with-debug-information-disabled-always-rebuilds)。
    要修复它,只需将文件名清除为“”(空字段)。

  2. "Forcing rebuild of all source files due to a change in the command line since the last build."
    这似乎也是一个已知的 VS 错误(https://connect.microsoft.com/VisualStudio/feedback/details/833943/forcing-rebuild-of-all-source-files-due-to-a-change-in- the-command-line-since-the-last-build)并且似乎在较新的版本中得到修复(但不是 VS2013)。我知道没有解决方法,但如果你这样做了,无论如何,把它张贴在这里。

回答by user3097514

Visual Studio 2013 -- "Forcing recompile of all source files due to missing PDB". I turned on detailed build output to locate the issue: I enabled "Detailed" build output under "Tools" → "Projects and Solutions" → "Build and Run".

Visual Studio 2013 --“由于缺少 PDB,强制重新编译所有源文件”。我打开了详细的构建输出来定位问题:我在“工具”→“项目和解决方案”→“构建和运行”下启用了“详细”构建输出。

I had several projects, all C++, I set the option for under project settings: (C/C++ → Debug Information Format) to Program Database (/Zi) for the problem project. However, this did not stop the problem for that project. The problem came from one of the other C++ projects in the solution.

我有几个项目,都是 C++,我在项目设置下设置了选项:(C/C++ → 调试信息格式)到问题项目的程序数据库(/Zi)。然而,这并没有阻止该项目的问题。问题来自解决方案中的其他 C++ 项目之一。

I set allC++ projects to "Program Database (/Zi)". This fixed the problem.

我将所有C++ 项目设置为“程序数据库 (/Zi)”。这解决了问题。

Again, the project reporting the problem was not the problem project. Try setting all projects to "Program Database (/Zi)" to fix the problem.

同样,报告问题的项目不是问题项目。尝试将所有项目设置为“程序数据库 (/Zi)”以解决问题。

回答by Christophe

Another simple solution referenced by Visual Studio Forum.

Visual Studio 论坛引用的另一个简单解决方案。

Changing configuration: menu ToolsOptionsProjects and SolutionsVC++ Project SettingsSolution Explorer Modeto Show all files.

更改配置:菜单ToolsOptionsProjects and SolutionsVC++ Project SettingsSolution Explorer Modeto Show all files

Then you can see all files in Solution Explorer.

然后您可以在解决方案资源管理器中看到所有文件。

Find the files marked by the yellow icon and remove them from the project.

找到黄色图标标记的文件并将它们从项目中删除。

It's OK.

没关系。