Skip to main content

Rewrite Visual Studio .vcxproj files without spurious changes

Project description

vcxproj-stream-editor

Simple Python library to parse Microsoft Visual Studio .vcxproj files and modify/rewrite without spurious changes

Usage:

Given the following simplified myproject.vcxproj:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="Globals">
    <ProjectGuid>{96F21549-A7BF-4695-A1B1-B43625B91A14}</ProjectGuid>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

Example 1 (input only):

import vcxproj

@vcxproj.coroutine
def print_project_guid():
    while True:
        action, params = yield
        if action == "start_elem" and params["name"] == "ProjectGuid":
            action, params = yield
            assert action == "chars"
            print("Project GUID is ", params["content"])

vcxproj.check_file("myproject.vcxproj", print_project_guid)

Output:

Project GUID is {96F21549-A7BF-4695-A1B1-B43625B91A14}

Example 2 (input and output):

import vcxproj

@vcxproj.coroutine
def remove_warning_level(target)
    while True:
        action, params = yield
        if action == "start_elem" and params["name"] == "WarningLevel":
            action, params = yield
            assert action == "chars"
            action, params = yield
            assert action == "end_elem"
            assert params["name"] == "WarningLevel"
            continue
        target.send((action, params))
        
vcxproj.filter_file("myproject.vcxproj", remove_warning_level, "myproject.stripped.vcxproj")

myproject.stripped.vcxproj will have the following content:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="Globals">
    <ProjectGuid>{96F21549-A7BF-4695-A1B1-B43625B91A14}</ProjectGuid>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
    </ClCompile>
  </ItemDefinitionGroup>
</Project>

Possible values for (action, params):

action params
start_elem {"name":<elem_name>, "attrs":{<attr1>:<value1>, <attr2>:<value2>}}
chars {"content":<content>}
end_elem {"name":<elem_name>}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcxproj_stream_editor-0.1.0.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

vcxproj_stream_editor-0.1.0-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page