簡體   English   中英

在powershell字符串的通配符為電話操作員

[英]Wildcard in powershell string for call operator

在powershell腳本中,我需要像這樣調用一個函數

$SpecRunCall = "./packages/SpecRun.Runner.1.2.0/tools/SpecRun.exe"
$MSTestArguments = @('run', 'Default.srprofile', "/baseFolder:.\TestResults", '/log:specrun.log')

if($tag) {
    $MSTestArguments += '/filter:@' + $tag
}   

& $SpecRunCall $MSTestArguments

但是我必須把SpecRun Runner的版本放在那里,我想為它設置一個通配符,然后找到我所擁有的任何版本(假設我只有一個版本),但我很難找到適合它的工作解決方案。

謝謝,

假設唯一的版本存在, Resolve-Path ...SpecRun.Runner.*...應該工作:

$SpecRunCall = Resolve-Path ./packages/SpecRun.Runner.*/tools/SpecRun.exe

假設所有SpecRunner版本都在標有版本號的不同文件夾中,您可以進行以下操作。 並且一次只有一個版本文件夾將在計算機上。

$version = "1.1.0","1.2.0","1.3.0"
$SpecRunCall = $null

$version | Foreach {
    # Set spec runner version folder
    $SpecFolder = "./packages/SpecRun.Runner.$_/"
    # Test folder 
    If(Test-path $SpecFolder){
        # Version folder found use it
        $SpecRunCall = $SpecFolder+"tools/SpecRun.exe"        
    }    
}

# Check if a version was found 
If($SpecRunCall -ne $null){
    # ** Your code ** 

    $MSTestArguments = @('run', 'Default.srprofile', "/baseFolder:.\TestResults", '/log:specrun.log')

    If($tag) {$MSTestArguments += '/filter:@' + $tag}   

    & $SpecRunCall $MSTestArguments
}

此代碼將獲取版本號列表並查找相應的SpecRunner文件夾。 如果發現選擇了SpecRunner版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM