Coverlet: Multiple Excludes don't work in Powershell

Created on 23 Aug 2018  路  14Comments  路  Source: coverlet-coverage/coverlet

I am trying to exclude multiple things but always getting an error when executing it in powershell:

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput="..\lcov.info" /p:Exclude="[*]*Examples?,[*]*Startup"

Also tried this but no luck either:

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput="..\lcov.info" /p:Exclude=\"[*]*Examples?,[*]*Startup\"

Am I doing something wrong or is this a bug?

The response is in both cases. If used alone both of them work just fine.

MSBUILD : error MSB1006: Property is not valid.
Switch: [*]*Startup

Most helpful comment

Hey guys, I've fiddled with this a bit and from https://github.com/Microsoft/msbuild/issues/471#issuecomment-366268743 the definitive way to fix this issue is to use %2c as the separator which msbuild will translate to ,

/p:Exclude="[*]*Examples?%2c[*]*Startup"

This should do the trick for all Powershell related property parsing errors. Looking for a contributor to help add this to the README

All 14 comments

Try surrounding the entire property declaration in quotes

"/p:Exclude=[*]*Examples?,[*]*Startup"

I came here to submit the same issue. From the PowerShell window in VSCode it's not possible to separate filters with a comma, not even when surrounding the filters with double quotes:

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info /p:Exclude="[StackState.Core*]*,[StackState.CLI*]*" .\StackState.Monitor.UnitTests\

Result:

MSBUILD : error MSB1006: Property is not valid. Switch: [StackState.CLI*]*

I have exactly the same issue when running 'dotnet test' in a VSTS build pipeline under a linux machine.
dotnet test /opt/vsts/work/1/s/src/MyAppName.Tests/MyAppName.Tests.csproj --configuration release --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=/opt/vsts/work/1/s/TestResults/Coverage/ /p:Exclude=\"[MyAppName.WebHost]*,[MyAppName.App]*,[MyAppName.DebugHost]*" --logger trx --results-directory /opt/vsts/work/_temp

Result:

2018-08-29T13:55:14.4149901Z MSBUILD : error MSB1006: Property is not valid.
2018-08-29T13:55:14.4170693Z Switch: [MyAppName.App]*

VSTS Task:
.Net Core
Version : 2.139.8

Surrounding the exclude argument with double quotes as suggested by @tonerdo did not work for me

Another weird thing, and I don't know whether this is the case with other people having this issue, is that the VSTS logs will show the command missing the first scaped double quote. The second double quote is escaped properly:
image

Try surrounding the entire property declaration in quotes

Thanks for the suggestion. I tried it but still run into the same error

Try this. Same as @tonerdo 's suggestion, but with single quotes and include escaped double quote
'/p:Exclude=\"[*]*Examples?,[*]*Startup\"'

Hey guys, I've fiddled with this a bit and from https://github.com/Microsoft/msbuild/issues/471#issuecomment-366268743 the definitive way to fix this issue is to use %2c as the separator which msbuild will translate to ,

/p:Exclude="[*]*Examples?%2c[*]*Startup"

This should do the trick for all Powershell related property parsing errors. Looking for a contributor to help add this to the README

Alternatively you can try using a response file https://github.com/tonerdo/coverlet/issues/30#issuecomment-383623772

/p:Exclude="[*]*Examples?%2c[*]*Startup"
Also we needed to use unescaped double quotes:
dotnet test --configuration $(buildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/ /p:Exclude="[MyAppName.DebugHost]*%2c[MyAppNamet.WebHost]*%2c[MyAppName.App]*"

This fixes it for us as well on a VSTS build. Thanx @tonerdo!

@tonerdo I am willing to help with the documentation. Should I include the %2c solution as the standard way to specify multiple excludes, or is it something exclusive to Powershell (and VSTS build)?

@glBeatriz thanks for volunteering. I think it's better to just add a note about Powershell under each section that involved separating property values with commas

@tonerdo I tried it and its working for me too. Thanks for investigating.
I leave this issue open until the documentation changes are done.

Created PR #191 regarding this issue

I stumbled upon the same issue when executing in an docker environment (microsoft/dotnet:latest) with .NET core.
%2C works as a workaround.

@tonerdo can we close this?Seems resolved by https://github.com/tonerdo/coverlet/pull/191

Was this page helpful?
0 / 5 - 0 ratings