Search code examples
c#.netcommand-linedotnet-testcoverlet

How to pass multi-valued arguments containing commas to a property in dotnet command line tool?


I want to run a command that includes this:

dotnet test /p:Exclude=\"*Test*,*Requirement*\"

The above is not the full command, but it's enough to provoke the parsing error. I am using the Coverlet NuGet package in my C# project and I want to exclude all projects that match those names.

I've read both here and here that enclosing the arguments in \"escaped quotes\" should do it, but it doesn't work. I get:

MSBUILD : error MSB1006: Property is not valid.
Switch: *Requirement*\

Using regular unescaped quotes gives the same error message:

dotnet test /p:Exclude="*Test*,*Requirement*"

Escaping the comma gives the same error message:

dotnet test /p:Exclude=*Test*\,*Requirement*

NOTE: The above example might not be correct Coverlet syntax. That's irrelevant for now. I just want to be able to pass a comma-separated list of values to one parameter. As it stands, dotnet rejects my syntax long before it reaches Coverlet.

I am running the commands from PowerShell.


Solution

  • It turns out that in PowerShell, %2c gets interpreted as a comma. So I can type this:

    dotnet test /p:Exclude=*Test*%2c*Requirement*