Skip to content

Commit c4a7c28

Browse files
authored
Merge pull request #726 from bgelens/fix/dotnet-global-tool-already-installed
AWSLambdaPSCore - Add dotnet global tool installed detection
2 parents 91d45ff + f0005f4 commit c4a7c28

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

PowerShell/Module/Private/_DeploymentFunctions.ps1

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,28 +324,31 @@ function _configureAmazonLambdaTools
324324
{
325325
Write-Host 'Restoring .NET Lambda deployment tool'
326326

327-
Write-Verbose -Message 'Installing .NET Global Tool Amazon.Lambda.Tools'
327+
# see if tool is already installed
328+
$amazonLambdaToolsInstalled = & dotnet tool list -g | Select-String -Pattern Amazon.Lambda.Tools -SimpleMatch -Quiet
328329

329330
# When "-Verbose" switch was used this output was not hidden.
330331
# Using stream redirection to force hide all output from the dotnet cli call
331-
& dotnet tool install -g Amazon.Lambda.Tools *>&1 | Out-Null
332-
333-
if ($LASTEXITCODE -ne 0)
332+
if (-not $amazonLambdaToolsInstalled)
334333
{
335-
Write-Verbose -Message 'Error installing, attempting to update Amazon.Lambda.Tools'
334+
Write-Verbose -Message 'Installing .NET Global Tool Amazon.Lambda.Tools'
335+
& dotnet tool install -g Amazon.Lambda.Tools *>&1 | Out-Null
336+
}
337+
else
338+
{
339+
Write-Verbose -Message 'Updating .NET Global Tool Amazon.Lambda.Tools'
336340

337341
# When "-Verbose" switch was used this output was not hidden.
338342
# Using stream redirection to force hide all output from the dotnet cli call
339343
& dotnet tool update -g Amazon.Lambda.Tools *>&1 | Out-Null
344+
}
340345

341-
if ($LASTEXITCODE -ne 0)
342-
{
343-
$msg = @"
346+
if ($LASTEXITCODE -ne 0) {
347+
$msg = @"
344348
Error configuring .NET CLI AWS Lambda deployment tools: $LastExitCode
345349
CALLSTACK:$(Get-PSCallStack | Out-String)
346350
"@
347-
throw $msg
348-
}
351+
throw $msg
349352
}
350353

351354
$toolsFolder = Join-Path -Path '~' -ChildPath '.dotnet' -AdditionalChildPath 'tools'

0 commit comments

Comments
 (0)