我决定创建一个“问题”,它是部分答案并与另一个问题相关(但可能有更好的答案。)这里的理由是我目前无法评论或发布到由于我的糟糕声誉,下面的这篇帖子......(我是这个网站的新手,我发现 another post on stack overflow linked here 的答案很有用,但他们最终没有回答我的问题。)
基本上,我发现当从在一组自动生成的 sln/vcproj 文件上在命令行上使用 MSBuild(包含在一组脚本中)切换到在 developer studio VS2013 中构建时,项目将完全重建。在 developer studio 中打开诊断并没有说明原因。
经过相当多的探索后,我发现这是因为当 MSBuild 进行构建时,在 tlog 目录中构建创建的扩展名为 .lastbuildstate 的深层文件包含条目
VCToolArchitecture=Native64Bit
然后,当我将项目加载到 developer studio 时,将对相同的配置进行完整的重建。构建将更改这些文件:现在它们将包含
VCToolArchitecture=Native32Bit
即使我确实在进行 64 位构建……我相信 MSBuild 和开发人员工作室实际上都是在进行 64 位构建的 32 位工具,所以为什么 MSBuild 编写 Native64Bit 在这里是个谜!
然后,在开发人员工作室中构建之前,在命令行构建之后,我编写了用 Native32Bit 替换 Native64Bit 的脚本,从而解决了这个问题。这似乎并没有重建一切,由此产生的 execs 似乎执行得很好......但我不禁觉得这种胡闹应该是不必要的。
很想知道其他人是否已经看到类似的问题以及更好的解决方法是什么(例如,是否有一些精通的 MSBuild 开关可以控制此问题?)
最佳答案
我决定将这篇文章标记为已回答,因为这个问题实际上是一个答案,但如果有用,这里有一个用 python 编写的脚本,可以帮助那些遇到与我遇到的问题类似的人。
脚本将遍历目录树(作为第一个参数提供)并编辑任何扩展名为“.lastbuildstate”的文件,以便将字符串 Native64Bit 替换为 Native32Bit。
如果您提供第二个参数,脚本将执行相反的操作,因此 Native32Bit 将替换为 Native64Bit。
import os
import string
def modify_file_without_changing_modification_time(file, to_32 = True):
if to_32 == True:
from_string = "Native64Bit"
to_string = "Native32Bit"
else:
from_string = "Native32Bit"
to_string = "Native64Bit"
mtime = os.path.getmtime(file)
atime = os.path.getatime(file)
newlines = None
with open(file,"r") as f:
lines = f.readlines()
newlines = [ string.join(string.split(line,from_string),to_string) for line in lines ]
with open(file,"w") as f:
for line in newlines:
f.write(line)
os.utime(file,(atime,mtime))
def set_buildstate(directory, to32):
for root, dirs, files in os.walk("."):
for name in files:
fullpath = os.path.join(root, name)
if os.path.splitext(fullpath)[1] == ".lastbuildstate":
modify_file_without_changing_modification_time(fullpath,to32)
if __name__ == "__main__":
import sys
# By default sets build state to 32 bit (which prevents developer studio rebuilds)
to_32 = True
if len(sys.argv) > 2:
to_32 = False
set_buildstate(sys.argv[1],to_32)
关于c++ - 64 位 VS2013 构建的 C++ 认为从命令行构建切换到开发人员工作室时代码已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37988777/