2016-08-19 45 views
0

我有我的.ps1在同一文件夹中如何加载PowerShell脚本,这是在不同的目录下,同时执行测试用例

enter image description here

一般我们用它来保存在directory1和MT .tests.ps1directory2写剧本时,测试文件和脚本文件都在同一个文件夹

$here = Split-Path -Parent $MyInvocation.MyCommand.Path 
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' 
. "$here\$sut" 

,但我有他们不同的文件夹中,如下所示,这样我怎么能工作正常加载路径,这样脚本文件应该得到加载

回答

0

有编码如下

$project = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace(".Tests", "") 
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".tests.", ".") 
. "$project\$sut" 
相关问题