BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Auto-escape MSBuild special characters in MsBuildArgument

Open Gal-lankri opened this issue 5 months ago • 5 comments

Summary

This PR adds automatic escaping of MSBuild-reserved characters in the MsBuildArgument class (e.g., ;, %, $, @, etc.), so users no longer need to manually encode these characters when passing MSBuild parameters.

Why

Previously, developers had to encode characters like semicolons manually (;%3B). This PR improves usability and correctness when passing multiple values to MSBuild properties such as DefineConstants.

Changes

  • Updated MsBuildArgument constructor to auto-escape special characters
  • Added a [Theory]-based test (EscapesSpecialCharactersCorrectly) to cover:
    • Semicolons
    • Percent
    • Dollar sign
    • At-symbol
    • Parentheses
    • Asterisk
    • Normal input (no escape)

Example

new MsBuildArgument("/p:DefineConstants=DEBUG;TRACE")
// becomes:
"/p:DefineConstants=DEBUG%3BTRACE"

Gal-lankri avatar May 13 '25 13:05 Gal-lankri