3

我正在尝试使用Cake作为构建工具,但在他们的 powershell 脚本中遇到了问题。

该脚本试图nuget.exe在环境变量路径中查找。如果它不存在,它会下载它。

问题是msbuild.exe总是返回,如果nuget.exe不存在,脚本会失败,因为它试图给我们msbuild.exe

$existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_) }

$NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1

无论exe我尝试使用此脚本搜索哪个,即使它存在,msbuild.exe也总是在列表中返回。

4

1 回答 1

3

我会使用不同的并且可能更有效的检查nuget.exe可用性

if (!(Get-Command nuget.exe -ErrorAction 0)) {
    # nuget.exe is not found, download ...
}

正如 Enrico Campidoglio 建议的那样,您可以添加-CommandType Application. 从理论上讲,它应该更有效。在(我的)实践中,情况并非总是如此。

于 2017-01-04T13:49:45.160 回答