1

I've decided to create a 'question' which is a partial answer and relates to another question (but to which there may well be better answers.) The rationale here is that I'm currently unable to comment or post to this post below due to my terrible reputation ... (I'm new to this site I found the answers to another post on stack overflow linked here useful, but they didnt in the end answer the question I had.)

Basically I was finding that projects would completely rebuild when switching from using MSBuild on the command line (wrapped up in a set of scripts) on a set of automatically generated sln/vcproj files to a build in developer studio VS2013. Turning on diagnostics in developer studio did not give any indication to why.

After a fair bit of poking around I discovered that the reason for this is that when MSBuild was doing the build, deep down files with the extension .lastbuildstate that get created by the build in the tlog directories contained the entry

VCToolArchitecture=Native64Bit

When I then loaded the project into developer studio, a complete rebuild would occur of the same configuration. The build would change these files: now they'd contain

VCToolArchitecture=Native32Bit

Even though I was definitely doing a 64 bit build ... both MSBuild and developer studio I believe are actually 32 bit tools that are doing a 64 bit build, so why MSBuild writes Native64Bit is a mystery here!

I was able to work around the problem then by scripting a replacement of Native64Bit with Native32Bit after a command line build before a build in developer studio. This then seems to not rebuild everything and the resultant execs seem to execute just fine ... but I cant help feeling that this sort of monkeying around should be unnecessary.

Intrigued to know if others have seen similar issues and what a better workaround would be (e.g. is there some masterful MSBuild switch that controls this?)

Community
  • 1
  • 1
user293026
  • 157
  • 1
  • 4

1 Answers1

-1

I've decided to mark this post answered as the question is effectively an answer, but if useful, here is a script, written in python, that may aid folk who have a similar problem to the one I was having.

The script will walk through the directory tree (provided as the first argument) and edit any files with the extension ".lastbuildstate" so that the string Native64Bit is replaced with Native32Bit.

If you provide a second argument the script will do the reverse so Native32Bit will be replaced with 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)
user293026
  • 157
  • 1
  • 4