2016-08-19 46 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" 
相關問題