Repository navigation
Escape MSBuild property values in the C# build command - #777
quantconnect-kronos[bot] merged 1 commit into
Conversation
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>
There was a problem hiding this comment.
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
masterand pass on this branch. The rest oftest_lean_runner.pypasses. - I ran the generated switch through
dotnet buildon the engine image's SDK (10.0.101).PathMapcame back as exactly the host path for/work/a;b/Algorithm,/work/a%3Bb/x,/work/a"band/work/it's $HOME, and NoWarn came back asMSB3277;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.
There was a problem hiding this comment.
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,NoWarnandConfigurationvalues through real MSBuild. Builds also succeed for semicolon, literal%3B, double-quote and shell-syntax host paths. - Tested end to end:
lean backtestfrom a workspace nameda;b. The base implementation fails withMSB1006; 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.
Closes #747
What changed
LeanRunner.set_up_csharp_optionsput the host compile root straight into thePathMapvalue 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/Algorithmfailed before compiling withMSB1006: 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%3Bjoin 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 wrongPathMap(%3Bbecame;, 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/pathmapparsing still rejects it (CS8101). The build fails for those paths just as it did before this change; issue #747 asks only about;.Tests
test_run_lean_passes_csharp_host_path_with_msbuild_syntax_as_one_property_value, for directoriesa;b,a,b,a%3Bb,a"banda;NoWarn=CS0001. It runs the generated build command through real Bash, parses the-p:argument the way MSBuild does, and checks thatPathMapis the exact host path,NoWarnisMSB3277;CS0618and no extra properties appear. All 5 cases fail onmasterand pass here.python -m pytest -s -rs: 2911 passed, 81 skipped.python static_analysis.py: passes, with no warnings in the changed files.dotnet msbuild/dotnet build10.0.101):PathMapfor/work/a;breaches the compiler intact and the build succeeds.MSB1006.%3Band"in a host path keep their literal characters.lean backteston a new C# project in a directory nameda;b.master: fails withMSBUILD : error MSB1006: Property is not valid.Build succeeded., then the backtest finished with 1 order and 1.693% net profit.