Last active
May 17, 2024 01:59
-
-
Save rajbos/b148e9833a5d08165188dbe00cc32301 to your computer and use it in GitHub Desktop.
Use dotnet tool to find out if a specific tool is installed on an environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Preface: | |
# dotnet tool install -g will return an error code when the tool is already installed in the system (at the same location) | |
# adding a test like below, will prevent the error | |
# this is mostly needed in a CI/CD environment where you don't want to break your pipeline if the tool was installed already. | |
# find if stryker is installed | |
$list = (dotnet tool list -g) | |
# echo the list | |
# $list | |
$strykerFound = ($list | Where-Object {$_.Split(' ')[0] -eq "dotnet-stryker"}) | |
if ($null -ne $StrykerFound) { | |
Write-Host "Installing Stryker" | |
dotnet tool install dotnet-stryker -g | |
} | |
else { | |
Write-Host "Stryker is already installed" | |
} | |
# stop powershell from reporting an error code | |
$global:LASTEXITCODE = 0 |
Your if logic is around the wrong way.
@distantcam it is not. This is best practice as well as the convention for PowerShell to prevent issues when the left side (the value) is already null. More info on MS Learn: docs
Your if logic is around the wrong way.
@distantcam it is not. This is best practice as well as the convention for PowerShell to prevent issues when the left side (the value) is already null. More info on MS Learn: docs
lol I mean if striker is found, it installs it, and if it's not found it doesn't install it. It should be this.
if ($null -eq $StrykerFound) {
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your if logic is around the wrong way.