Get the confs
Input collapsed: from surun_tools.glob1 import glob_files glob_files("*.vcxproj") [WindowsPath('C:/src/surun/src/PC/InstallSuRun.vcxproj'), WindowsPath('C:/src/surun/src/PC/SuRun.vcxproj'), WindowsPath('C:/src/surun/src/PC/SuRunExt.vcxproj'), WindowsPath('C:/src/surun/tests/TestScreenshot/TestScreenshot.vcxproj'), WindowsPath('C:/src/surun/tests/TestScreenshotSuRun/TestScreenshotSuRun.vcxproj')] some confs are test projects. filter out them
proj_files = list(filter(lambda x: "test" not in str(x), glob_files("*.vcxproj"))) proj_files [WindowsPath('C:/src/surun/src/PC/InstallSuRun.vcxproj'), WindowsPath('C:/src/surun/src/PC/SuRun.vcxproj'), WindowsPath('C:/src/surun/src/PC/SuRunExt.vcxproj')] Select a demo proj file
ext_proj = glob_files("*.vcxproj")[2] print(ext_proj) C:\src\surun\src\PC\SuRunExt.vcxproj from lxml import etree parser = etree.XMLParser(remove_comments=False) tree = etree.parse(ext_proj, parser) def is_correct_conf(s: str) -> bool: if "x64 Unicode Debug|x64" in s: return True elif "SuRun32 Unicode Debug|Win32" in s: return True return False def save(): global tree tree.write(ext_proj, encoding="utf-8", xml_declaration=True) from pathlib import Path content = Path(ext_proj).read_text(encoding="utf8") content = content.replace("ns0:", "").replace(":ns0", "").replace('/>', ' />') Path(ext_proj).write_text(content, encoding="utf8") # idea from Gemini ns = {"default": "http://schemas.microsoft.com/developer/msbuild/2003"} def remove(tag, tag2="Condition"): tag = "/".join(map(lambda x: "default:" + x, tag.split("/"))) root = tree.getroot() for i in root.findall(f"{tag}", ns): if tag2 not in i.attrib: continue if not is_correct_conf(i.attrib[tag2]): i.getparent().remove(i) save() Test gradually
...