Reputation: 16845
I am trying to run MSTest
in Powershell. One of the options to pass is /testcontainer
and it can be passed multiple times.
In my script I need to build the option string as I can have many test containers passed to the script, thus this is what I do:
param(
[string[]] $TestContainers = @(
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test1.dll',
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test2.dll',
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test3.dll',
'C:\Users\myuser\MyProject\test\Test1\bin\Debug\Test4.dll'
)
);
$TestContainersOptions = @();
foreach ($TestContainer in $TestContainers)
{
$TestContainersOptions += "/testcontainer:'$TestContainer'";
}
$MSTestPath = "C:\Program...\MsTest.exe"
& $MSTestPath $TestContainersOptions;
When I run the script I get:
Microsoft (R) Test Execution Command Line Tool Version 14.0.23107.0 Copyright (c) Microsoft Corporation. All rights reserved.
The given path's format is not supported. For switch syntax, type "MSTest /help"
What to do?
Upvotes: 0
Views: 594
Reputation: 174425
Enclose each path in "
(escape sequence for double-quotes is just two in a row, ""
):
$TestContainersOptions = foreach ($TestContainer in $TestContainers)
{
"/testcontainer:""$TestContainer"""
}
If you assign the output from the foreach
loop directly to the variable (as shown above), you don't have to declare it as an array beforehand
Upvotes: 1