我正在尝试从 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
运行 MSTest.exe .更重要的是,我将获取当前目录中的所有程序集并将它们设置为单独的/testcontainer 参数。如果没有 PowerShell 提示,我无法弄清楚如何做到这一点。
$CurrentDirectory = [IO.Directory]::GetCurrentDirectory()
$MSTestCall = '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"'
foreach($file in Get-ChildItem $CurrentDirectory)
{
if($file.name -match "\S+test\S?.dll$" )
{
$MSTestArguments += "/TestContainer:" + $file + " "
}
}
$MSTestArguments += " /resultsFile:out.trx"
$MSTestArguments += " /testsettings:C:\someDirectory\local64.testsettings"
Invoke-Expression "$MSTestCall $MSTestArguments"
我从这段代码中得到的错误是:
Invoke-Expression : You must provide a value expression on the right-hand side of the '/' operator.
当我尝试在名称中没有空格的目录中调用 mstest.exe 时,我没有收到此错误(不需要额外的“”)。
当我尝试使用
&
,&$MSTestCall $MSTestArguments
它将 $MSTestArguments 作为单个参数传递,MSTest 立即抛出。建议?
最佳答案
我建议您使用参数数组和运算符 &
.在此处查看我的回答中的示例:Executing a Command stored in a Variable from Powershell
在这种情况下,代码应该是这样的:
$MSTestCall = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe"
$MSTestArguments = @('/resultsFile:out.trx', '/testsettings:C:\someDirectory\local64.testsettings')
foreach($file in Get-ChildItem $CurrentDirectory)
{
if($file.name -match "\S+test\S?.dll$" )
{
$MSTestArguments += "/TestContainer:" + $file
}
}
& $MSTestCall $MSTestArguments
关于powershell - 使用 PowerShell 从包含空格的目录运行 EXE 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3868342/