Skip to content

Feature Request: Add MsBuildArgument supports for MSBuild special characters #2719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
filzrev opened this issue Apr 23, 2025 · 2 comments · May be fixed by #2729
Open

Feature Request: Add MsBuildArgument supports for MSBuild special characters #2719

filzrev opened this issue Apr 23, 2025 · 2 comments · May be fixed by #2729

Comments

@filzrev
Copy link
Contributor

filzrev commented Apr 23, 2025

Currently MsBuildArgument constructor accept single string argument.
And this string value is passed to MSBuild command line parameter as is.

So when specified string contains MSBuild special characters
It needs manually escape these characters.
(e.g. When passing list values. It need to escape semicolon(;) char to %3B)

Is it able to handle these special characters inside MsBuildArgument class?
or add [MsBuildArgument constructor] that accept string params to handle multiple values?

Test Code

    internal class Program
    {
        static void Main(string[] args)
        {
            BenchmarkRunner.Run<Benchmarks>();
        }
    }

    [Config(typeof(CustomConfig))]
    public class Benchmarks
    {
        [Benchmark]
        public void Benchmark01()
        {
#if TEST1 && TEST2
            // DefineConstants symbols are defined as expected.
#else
            throw new Exception("DefineConstants value is unexpected value!");
#endif
        }

        public class CustomConfig : ManualConfig
        {
            public CustomConfig()
            {
                AddLogger(ConsoleLogger.Default);

                AddColumnProvider(DefaultConfig.Instance.GetColumnProviders().ToArray());
              
                AddJob(Job.ShortRun
                    .WithStrategy(RunStrategy.Monitoring)
                    .WithArguments(
                    [
                       // new MsBuildArgument("/p:DefineConstants=TEST1;TEST2"),     // Error: MSBUILD : error MSB1006: Property is not valid.
                       // new MsBuildArgument("/p:DefineConstants=\"TEST1;TEST2\""), // Double quote does not works.
                       new MsBuildArgument("/p:DefineConstants=TEST1%3BTEST2"),      // It works when using MSBuild special character
                    ])
                    .WithId("CustomJob"));

                WithOption(ConfigOptions.KeepBenchmarkFiles, true); // Use this settings for output to JobId folder
            }
        }
    }
@timcassell
Copy link
Collaborator

I think it's reasonable to escape those characters in the MsBuildArgument ctor.

@filzrev
Copy link
Contributor Author

filzrev commented May 3, 2025

Double quote does not works.

It seems double quote is stripped on .bat execution timing.
So, it need to escape " char also on Windows environment.
(e.g. new MsBuildArgument("/p:DefineConstants=\\\"TEST1;TEST2\\\""))

I'll try to create PR later to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants