Serve Laurijssen
Serve Laurijssen

Reputation: 9733

programmatically alter project settings

I have an old MFC solution with 120 projects in it. Now Im trying to compile it with VisualC 2017 but every project emits the error:

cannot open file mfc140d.lib

Opening project properties, change the platform toolset to VS2017 141 and the the language version to C++17 fixes it. But it will take a looooong time to do this for 120 projects and then the same for release build. Which are the settings in the project files that I can change programatically to set these two options? I sure cant find them

Upvotes: 2

Views: 361

Answers (1)

Serve Laurijssen
Serve Laurijssen

Reputation: 9733

Wrote a python script that adds stdcpp17 and v141 to the vcxproj file if non existing. Maybe somebody finds a use for it:

def get_all_files(basedir):
    for root, subfolders, files in os.walk(basedir):
        for file in os.listdir(root):
            yield root, file

def all_lines_from_file(file):
    with open(file, 'r') as fd:
        for line in fd.readlines():
            yield line

def update_VCXPROJ():
    standard = '<LanguageStandard>stdcpp17</LanguageStandard>'
    toolset = '<PlatformToolset>v141</PlatformToolset>'
    add1 = '<CharacterSet>MultiByte</CharacterSet>'
    add2 = '<DebugInformationFormat>'

    for root, file in get_all_files('c:/projects/6thcycle/sources/'):
        if not file.lower().endswith('.vcxproj'):
            continue

        thisfile = ''
        for line in all_lines_from_file('{0}/{1}'.format(root, file)):
            if toolset in line or standard in line:
                continue

            if add1 in line:
                line += '    {0}\n'.format(toolset)
            elif add2 in line:
                line += '      {0}\n'.format(standard)

            thisfile += line

        with open('{0}/{1}'.format(root, file), 'w') as fd:
            fd.write(thisfile)    

update_VCXPROJ()

Upvotes: 1

Related Questions