简体   繁体   English

在powershell字符串的通配符为电话操作员

[英]Wildcard in powershell string for call operator

In a powershell script I need to call a funcion like this 在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

But I have to put there the version of the SpecRun Runner, I was thinking of putting a wildcard for that and then find whichever version I have (provided I have only one there) but I'm struggling to find a working solution for it. 但是我必须把SpecRun Runner的版本放在那里,我想为它设置一个通配符,然后找到我所拥有的任何版本(假设我只有一个版本),但我很难找到适合它的工作解决方案。

Thanks, 谢谢,

假设唯一的版本存在, Resolve-Path ...SpecRun.Runner.*...应该工作:

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

You could the following assuming that all the SpecRunner version are all in different folders labeled with the version number. 假设所有SpecRunner版本都在标有版本号的不同文件夹中,您可以进行以下操作。 And that only one version folder will be on the computer at a time. 并且一次只有一个版本文件夹将在计算机上。

$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
}

This code will take a list of version numbers and look for the corresponding SpecRunner folder. 此代码将获取版本号列表并查找相应的SpecRunner文件夹。 If found that version of SpecRunner is selected. 如果发现选择了SpecRunner版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM