我尝试从 powershell 执行 Visual Studio 的工具 MSTest,但没有成功:
$testDLL = "myTest.dll"
$mstestPath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"
$arguments = " /testcontainer:" + $testDLL + " /test:UnitTest1"
Invoke-Expression "$mstestPath $arguments"
我收到此错误:“术语‘x86’未被识别为 cmdlet、函数...的名称” 任何想法?谢谢。
编辑:
好吧,问题是使用“&”而不是“Invoke-Expression”解决的,并为每个参数创建单独的变量,它对我来说只在一个变量中使用这两个变量不起作用:
$testDLL = "myTest.dll"
$mstestPath = "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe"
$argument1 = "/testcontainer:" + $testDLL
$argument2 = "/test:UnitTest1"
& $mstestPath $argument1
最佳答案
我建议在这种情况下使用 &
运算符(请参阅 David Brabant 的评论)。
但是,如果您必须使用 Invoke-Expression,则可以将 $mstestPath
转换为其等效的短路径。
$testDLL = "myTest.dll"
$fs = New-Object -ComObject Scripting.FileSystemObject
$f = $fs.GetFile("C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\mstest.exe")
$mstestPath = $f.shortpath
$arguments = " /testcontainer:" + $testDLL + " /test:UnitTest1"
Invoke-Expression "$mstestPath $arguments"
关于powershell - 使用 Powershell 调用 MSTest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16914125/