Skip to content

Multiple Excludes don't work in Powershell #182

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

Closed
dlerps opened this issue Aug 23, 2018 · 15 comments
Closed

Multiple Excludes don't work in Powershell #182

dlerps opened this issue Aug 23, 2018 · 15 comments

Comments

@dlerps
Copy link

dlerps commented Aug 23, 2018

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
@tonerdo
Copy link
Collaborator

tonerdo commented Aug 25, 2018

Try surrounding the entire property declaration in quotes

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

@rvanmaanen
Copy link

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*]*

@ghost
Copy link

ghost commented Aug 29, 2018

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

@dlerps
Copy link
Author

dlerps commented Aug 29, 2018

Try surrounding the entire property declaration in quotes

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

@khairuddinniam
Copy link

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

@tonerdo
Copy link
Collaborator

tonerdo commented Sep 1, 2018

Hey guys, I've fiddled with this a bit and from dotnet/msbuild#471 (comment) 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

@tonerdo
Copy link
Collaborator

tonerdo commented Sep 1, 2018

Alternatively you can try using a response file #30 (comment)

@ghost
Copy link

ghost commented Sep 3, 2018

/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!

@ghost
Copy link

ghost commented Sep 5, 2018

@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)?

@tonerdo
Copy link
Collaborator

tonerdo commented Sep 5, 2018

@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

@dlerps
Copy link
Author

dlerps commented Sep 7, 2018

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

@ghost
Copy link

ghost commented Sep 10, 2018

Created PR #191 regarding this issue

@breigo
Copy link

breigo commented May 9, 2019

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

@MarcoRossignoli
Copy link
Collaborator

@tonerdo can we close this?Seems resolved by #191

@jrichardsz
Copy link

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

What a martian way to run tests :/

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

No branches or pull requests

7 participants