-
-
Notifications
You must be signed in to change notification settings - Fork 998
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
base: master
Are you sure you want to change the base?
Conversation
@dotnet-policy-service agree |
I would rather something like this be implemented as a new type |
- 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.
|
||
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"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)}") |
There was a problem hiding this comment.
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.
: 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() |
There was a problem hiding this comment.
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.
Added MsBuildArgument(string key, params string[] values) constructor.
Implemented escaping of semicolons in argument values.