Skip to content

Add MsBuildArgument constructor supporting multiple values #2732

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
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jespernapp
Copy link

Added MsBuildArgument(string key, params string[] values) constructor.
Implemented escaping of semicolons in argument values.

@jespernapp
Copy link
Author

@dotnet-policy-service agree

@timcassell
Copy link
Collaborator

I would rather something like this be implemented as a new type public class MsBuildProperty : MsBuildArgument. Also, it seems that wrapping the values in quotes is sufficient without escaping the semicolons (#2730 (comment)).

- Introduced MsBuildProperty class inheriting from MsBuildArgument  that wraps multiple values in quotes and separates them with semicolons.

- AddedtestMsBuildProperty_ShouldWrapMultipleValuesInQuotes to verify correct text representation formatting.
Comment on lines +64 to +76

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");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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");
}

public class MsBuildProperty : MsBuildArgument
{
public MsBuildProperty(string key, params string[] values)
: base($"/p:{key}=\"{string.Join(";", values)}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that quotes need to be escaped to work cross-platform.

Suggested change
: base($"/p:{key}=\"{string.Join(";", values)}")
: base($"/p:{key}=\\\"{string.Join(";", values)}\\\"")

@@ -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.

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

Successfully merging this pull request may close these issues.

2 participants