Skip to content

Escape MSBuild property values in the C# build command - #777

Merged
quantconnect-kronos[bot] merged 1 commit into
masterfrom
kronos/bug-747-escape-msbuild-property-values
Nov 23, 2026
Merged

quantconnect-kronos[bot] merged 1 commit into
masterfrom
kronos/bug-747-escape-msbuild-property-values

Conversation

@quantconnect-kronos

Copy link
Copy Markdown
Contributor

Closes #747

What changed

LeanRunner.set_up_csharp_options put the host compile root straight into the PathMap value and joined all properties with ; in one -p: switch. Shell quoting kept the argument whole, but MSBuild still splits that switch on ; and ,, drops " and unescapes %XX. A C# project under a host directory like /work/a;b/Algorithm failed before compiling with MSB1006: Property is not valid.

Each property value now passes ;, ,, % and " as %XX, which MSBuild turns back into the original characters. Shell quoting of the whole argument stays as it was. NoWarn codes go through the same escaping, so the hand-written %3B join became a plain ; join. The generated switch is the same as before for values that have none of these characters, NoWarn included (NoWarn=MSB3277%3BCS0618).

Before this change, a host path with % or " also built, but with the wrong PathMap (%3B became ;, and " was dropped). Now it gets the real path.

Not covered: a host path with , or = now gets through MSBuild, but the C# compiler's own /pathmap parsing still rejects it (CS8101). The build fails for those paths just as it did before this change; issue #747 asks only about ;.

Tests

  • New test_run_lean_passes_csharp_host_path_with_msbuild_syntax_as_one_property_value, for directories a;b, a,b, a%3Bb, a"b and a;NoWarn=CS0001. It runs the generated build command through real Bash, parses the -p: argument the way MSBuild does, and checks that PathMap is the exact host path, NoWarn is MSB3277;CS0618 and no extra properties appear. All 5 cases fail on master and pass here.
  • python -m pytest -s -rs: 2911 passed, 81 skipped.
  • python static_analysis.py: passes, with no warnings in the changed files.
  • With the real .NET SDK (dotnet msbuild/dotnet build 10.0.101):
    • The escaped PathMap for /work/a;b reaches the compiler intact and the build succeeds.
    • The unescaped value fails with MSB1006.
    • %3B and " in a host path keep their literal characters.
  • Tested end to end: lean backtest on a new C# project in a directory named a;b.
    • master: fails with MSBUILD : error MSB1006: Property is not valid.
    • This branch: Build succeeded., then the backtest finished with 1 order and 1.693% net profit.

A host path with ";" in the PathMap property split the -p: switch into
more properties, so MSBuild rejected the build. Values now pass ";", ",",
"%" and '"' in their %XX form, which MSBuild unescapes back to the
original characters. NoWarn codes go through the same escaping.

Closes #747

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. A ; in the host compile root no longer splits the -p: switch. Every other property comes out byte-for-byte the same, NoWarn included (MSB3277%3BCS0618).

Verified:

  • The 5 new cases fail on master and pass on this branch. The rest of test_lean_runner.py passes.
  • I ran the generated switch through dotnet build on the engine image's SDK (10.0.101). PathMap came back as exactly the host path for /work/a;b/Algorithm, /work/a%3Bb/x, /work/a"b and /work/it's $HOME, and NoWarn came back as MSB3277;CS0618.

The description says the C# compiler still rejects , and = in host paths (CS8101), same as on master. That's outside what #747 asks for, so it doesn't block this change.

Risk: risk:low. This is a small, easily reverted fix to how one argument is encoded. Paths that build today generate the same switch as before. It has tests that fail without the fix, green CI and an end-to-end backtest.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added risk:low Low risk and removed kronos:review:working review: in progress labels Nov 23, 2026
@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 23, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued and removed kronos:review Request review labels Nov 23, 2026
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review:working review: in progress and removed kronos:review:queued review: queued labels Nov 23, 2026

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I found no blocking regression introduced by this change.

Independent verification:

  • PYTHONPATH="$PWD" python -m pytest -q: 2,911 passed, 81 skipped. All five new cases fail with the base implementation.
  • The generated arguments preserve exact PathMap, NoWarn and Configuration values through real MSBuild. Builds also succeed for semicolon, literal %3B, double-quote and shell-syntax host paths.
  • Tested end to end: lean backtest from a workspace named a;b. The base implementation fails with MSB1006; this branch builds and completes the backtest with one order.
  • Static analysis passes, with five existing unused-import warnings outside the changed files.

A separately reproduced, pre-existing warning-suppression problem is tracked in #782; it does not block this fix.

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot removed the kronos:review:working review: in progress label Nov 23, 2026
@quantconnect-kronos
quantconnect-kronos Bot merged commit bfdafa4 into master Nov 23, 2026
60 checks passed
@quantconnect-kronos
quantconnect-kronos Bot deleted the kronos/bug-747-escape-msbuild-property-values branch November 23, 2026 15:23
@quantconnect-kronos quantconnect-kronos Bot removed the kronos:develop:working develop: in progress label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Low risk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semicolons in C# host paths are interpreted as MSBuild property separators

0 participants