Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/BenchmarkDotNet/Jobs/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,34 @@ public MonoArgument(string value) : base(value)
/// example: new MsBuildArgument("/p:MyCustomSetting=123")
/// </summary>
[PublicAPI]

/// <summary>
/// A specialized MSBuild argument that sets a property using a quoted, semicolon-separated list of values.
/// </summary>
public class MsBuildProperty : MsBuildArgument
{
public MsBuildProperty(string key, params string[] values)
: base($"/p:{key}=\"{string.Join(";", values)}")
{
}


}
public class MsBuildArgument : Argument
{
public MsBuildArgument(string value) : base(value) { }

public MsBuildArgument(string key, params string[] values)
: base($"/p:{key}={EscapeAndJoin(values)}") { }

private static string EscapeAndJoin(string[] values)
{
return string.Join("%3b", values.Select(EscapeSpecialChars));
}

private static string EscapeSpecialChars(string input)
{
return input.Replace(";", "%3B");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public void ProcessIsBuiltWithCustomProperty(bool setCustomProperty)
CanExecute<PropertyDefine>(config);
}

[Fact]

public void MsBuildProperty_ShouldWrapMultipleValuesInQuotes()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move this test to BenchmarkDotNet.Tests project, and add a real integration test in BenchmarkDotNet.IntegrationTests project.

{
var arg = new MsBuildProperty("DefineConstants", "FOO", "BAR");
Assert.Equal("/p:DefineConstants=\"FOO;BAR\"", arg.TextRepresentation);
}
[Fact]
public void MultipleProcessesAreBuiltWithCorrectProperties()
{
Expand Down
Loading