Skip to content

Instantly share code, notes, and snippets.

@aggieben
Last active July 20, 2017 21:52
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aggieben/953345520eb1b9a6df58c5158f7249d6 to your computer and use it in GitHub Desktop.
Save aggieben/953345520eb1b9a6df58c5158f7249d6 to your computer and use it in GitHub Desktop.
List installed .NET Core SDK versions
#!/bin/sh
# Benjamin Collins <aggieben@gmail.com>
# Requires GNU readlink (get on macOS with `brew install coreutils`)
READLINK=${READLINK:-readlink}
cliPath=$(which dotnet)
netDir=$(dirname $($READLINK -f $cliPath))
ls -1 "$netDir/sdk"
REM - from http://joshua.poehls.me/powershell-batch-file-wrapper/
@ECHO OFF
SET SCRIPTNAME=%~d0%~p0%~n0.ps1
SET ARGS=%*
IF [%ARGS%] NEQ [] GOTO ESCAPE_ARGS
:POWERSHELL
PowerShell.exe -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Unrestricted -Command "& { & '%SCRIPTNAME%' @args; EXIT $LASTEXITCODE }" %ARGS%
EXIT /B %ERRORLEVEL%
:ESCAPE_ARGS
SET ARGS=%ARGS:"=\"%
SET ARGS=%ARGS:`=``%
SET ARGS=%ARGS:'=`'%
SET ARGS=%ARGS:$=`$%
SET ARGS=%ARGS:{=`}%
SET ARGS=%ARGS:}=`}%
SET ARGS=%ARGS:(=`(%
SET ARGS=%ARGS:)=`)%
SET ARGS=%ARGS:,=`,%
SET ARGS=%ARGS:^%=%
GOTO POWERSHELL
<#
.SYNOPSIS
Lists installed versions of the .NET Core SDK.
.NOTES
Version: 1.0
Author: Ben Collins <aggieben@gmail.com>
Creation Date: 1/5/2017
#>
#$DebugPreference = "Continue"
$cliPath = Get-Command dotnet.exe | Select-Object -ExpandProperty Source
Write-Debug "Using $cliPath"
$netDir = Split-Path $cliPath
Get-ChildItem "$netDir/sdk" | Select-Object -ExpandProperty Name
@tiy-curtissimo
Copy link

It seems that he new dotnet installations on macOS don't use a link, so it fails. For macOS, this works on my machine:

cliPath=$(which dotnet)
netDir=$(dirname $cliPath)

ls -1 "$netDir/sdk"

@aggieben
Copy link
Author

aggieben commented Jul 20, 2017

@tiy-curtissimo: thanks for the tip. I'll get the scripts updated soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment