使用 PowerShell 从包含空格的目录运行 EXE 文件
我正在尝试从 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:您必须在“/”运算符的右侧提供一个值表达式。
当我尝试在名称中没有空格的目录中调用 mstest.exe 时,我不会收到此错误(不需要额外的“)。
当我尝试使用 &
时,
&$MSTestCall $MSTestArguments
它将 $MSTestArguments 作为单个参数传递,MSTest 会立即抛出哪个参数?
I'm trying to run MSTest.exe from C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
. What's more, I'm taking all of the assemblies in my current directory and setting them as separate /testcontainer arguments. I cannot figure out how to do this without PowerShell complaining.
$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"
The error I get from this code is:
Invoke-Expression : You must provide a value expression on the right-hand side of the '/' operator.
I don't get this error when I try to call a mstest.exe in a directory without a space in the name (no additional "'s are needed).
When I try using &
,
&$MSTestCall $MSTestArguments
It hands $MSTestArguments over as a single argument, which MSTest prompty throws out. Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您使用参数数组和运算符
&
。请参阅我的答案中的示例: 执行Powershell 中存储在变量中的命令在本例中,代码应如下所示:
I would recommend you to use an array of parameters and the operator
&
. See the examples in my answer in here: Executing a Command stored in a Variable from PowershellIn this case the code should be something like this:
这有效吗?
Does this work?