Rename dotnetsdk to kvm

This commit is contained in:
Wei Wang 2015-01-28 16:31:17 -08:00
parent 19de5f1be1
commit 6c55b360d0
9 changed files with 630 additions and 675 deletions

View File

@ -20,9 +20,9 @@ IF EXIST packages\KoreBuild goto run
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion
IF "%SKIP_KRE_INSTALL%"=="1" goto run
CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86
CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86
CALL packages\KoreBuild\build\kvm upgrade -runtime CLR -x86
CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86
:run
CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86
CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

View File

@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then
fi
if ! type k > /dev/null 2>&1; then
source packages/KoreBuild/build/dotnetsdk.sh
source packages/KoreBuild/build/kvm.sh
fi
if ! type k > /dev/null 2>&1; then
dotnetsdk upgrade
kvm upgrade
fi
mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"

View File

@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then
fi
if ! type k > /dev/null 2>&1; then
source packages/KoreBuild/build/dotnetsdk.sh
source packages/KoreBuild/build/kvm.sh
fi
if ! type k > /dev/null 2>&1; then
dotnetsdk upgrade
kvm upgrade
fi
mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"

View File

@ -56,5 +56,5 @@ projectFile=''
}
}
macro name='K' command='string' workingdir='string' dotnetsdkUse='string'
macro name='K' command='string' workingdir='string' kvmUse='string'
k

View File

@ -1,17 +1,17 @@
@{/*
k
Run dotnet commands in your project. Executes k cmd.
Run klr commands in your project. Executes k cmd.
command=''
dotnetsdkUse=''
kvmUse=''
*/}
default dotnetsdkUse=''
default kvmUse=''
var dotnetsdkPath='${Directory.GetCurrentDirectory()}\packages\KoreBuild\build\dotnetsdk'
var kvmPath='${Directory.GetCurrentDirectory()}\packages\KoreBuild\build\kvm'
exec program='cmd' commandline='/C k ${command}' if='!IsMono && string.IsNullOrEmpty(dotnetsdkUse)'
exec program='cmd' commandline='/C "${dotnetsdkPath}" use ${dotnetsdkUse} && k ${command}' if='!IsMono && !string.IsNullOrEmpty(dotnetsdkUse)'
exec program='cmd' commandline='/C k ${command}' if='!IsMono && string.IsNullOrEmpty(kvmUse)'
exec program='cmd' commandline='/C "${kvmPath}" use ${kvmUse} && k ${command}' if='!IsMono && !string.IsNullOrEmpty(kvmUse)'
exec program='k' commandline='${command}' if='IsMono'

View File

@ -1,412 +0,0 @@
# dotnetsdk.sh
# Source this file from your .bash-profile or script to use
_dotnetsdk_has() {
type "$1" > /dev/null 2>&1
return $?
}
if _dotnetsdk_has "unsetopt"; then
unsetopt nomatch 2>/dev/null
fi
if [ -z "$DOTNET_USER_HOME" ]; then
eval DOTNET_USER_HOME=~/.dotnet
fi
DOTNET_USER_PACKAGES="$DOTNET_USER_HOME/runtimes"
if [ -z "$DOTNET_FEED" ]; then
DOTNET_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
fi
_dotnetsdk_find_latest() {
local platform="mono"
if ! _dotnetsdk_has "curl"; then
echo 'dotnetsdk needs curl to proceed.' >&2;
return 1
fi
local url="$DOTNET_FEED/GetUpdates()?packageIds=%27dotnet-$platform%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
xml="$(curl $url 2>/dev/null)"
echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1
version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')"
echo $version
}
_dotnetsdk_strip_path() {
echo "$1" | sed -e "s#$DOTNET_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$DOTNET_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$DOTNET_USER_PACKAGES/[^/]*$2[^:]*##g"
}
_dotnetsdk_prepend_path() {
if [ -z "$1" ]; then
echo "$2"
else
echo "$2:$1"
fi
}
_dotnetsdk_package_version() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/[^.]*.\(.*\)/\1/"
}
_dotnetsdk_package_name() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/\([^.]*\).*/\1/"
}
_dotnetsdk_package_runtime() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/KRE-\([^.-]*\).*/\1/"
}
_dotnetsdk_download() {
local runtimeFullName="$1"
local runtimeFolder="$2"
local pkgName=$(_dotnetsdk_package_name "$runtimeFullName")
local pkgVersion=$(_dotnetsdk_package_version "$runtimeFullName")
local url="$DOTNET_FEED/package/$pkgName/$pkgVersion"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
if [ -e "$runtimeFolder" ]; then
echo "$runtimeFullName already installed."
return 0
fi
echo "Downloading $runtimeFullName from $DOTNET_FEED"
if ! _dotnetsdk_has "curl"; then
echo "dotnetsdk needs curl to proceed." >&2;
return 1
fi
mkdir -p "$runtimeFolder" > /dev/null 2>&1
local httpResult=$(curl -L -D - "$url" -o "$runtimeFile" 2>/dev/null | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
[[ $httpResult == "404" ]] && echo "$runtimeFullName was not found in repository $DOTNET_FEED" && return 1
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $runtimeFullName from $DOTNET_FEED" && return 1
_dotnetsdk_unpack $runtimeFile $runtimeFolder
return $?
}
_dotnetsdk_unpack() {
local runtimeFile="$1"
local runtimeFolder="$2"
echo "Installing to $runtimeFolder"
if ! _dotnetsdk_has "unzip"; then
echo "dotnetsdk needs unzip to proceed." >&2;
return 1
fi
unzip $runtimeFile -d $runtimeFolder > /dev/null 2>&1
[ -e "$runtimeFolder/[Content_Types].xml" ] && rm "$runtimeFolder/[Content_Types].xml"
[ -e "$runtimeFolder/_rels/" ] && rm -rf "$runtimeFolder/_rels/"
[ -e "$runtimeFolder/package/" ] && rm -rf "$runtimeFolder/_package/"
#Set shell commands as executable
find "$runtimeFolder/bin/" -type f \
-exec sh -c "head -c 11 {} | grep '/bin/bash' > /dev/null" \; -print | xargs chmod 775
}
_dotnetsdk_requested_version_or_alias() {
local versionOrAlias="$1"
local runtimeBin=$(_dotnetsdk_locate_runtime_bin_from_full_name "$versionOrAlias")
# If the name specified is an existing package, just use it as is
if [ -n "$runtimeBin" ]; then
echo "$versionOrAlias"
else
if [ -e "$DOTNET_USER_HOME/alias/$versionOrAlias.alias" ]; then
local runtimeFullName=$(cat "$DOTNET_USER_HOME/alias/$versionOrAlias.alias")
local pkgName=$(echo $runtimeFullName | sed "s/\([^.]*\).*/\1/")
local pkgVersion=$(echo $runtimeFullName | sed "s/[^.]*.\(.*\)/\1/")
local pkgPlatform=$(echo "$pkgName" | sed "s/dotnet-\([^.-]*\).*/\1/")
else
local pkgVersion=$versionOrAlias
local pkgPlatform="mono"
fi
echo "dotnet-$pkgPlatform.$pkgVersion"
fi
}
# This will be more relevant if we support global installs
_dotnetsdk_locate_runtime_bin_from_full_name() {
local runtimeFullName=$1
[ -e "$DOTNET_USER_PACKAGES/$runtimeFullName/bin" ] && echo "$DOTNET_USER_PACKAGES/$runtimeFullName/bin" && return
}
dotnetsdk()
{
if [ $# -lt 1 ]; then
dotnetsdk help
return
fi
case $1 in
"help" )
echo ""
echo ".NET SDK Manager - Build 10206"
echo ""
echo "USAGE: dotnetsdk <command> [options]"
echo ""
echo "dotnetsdk upgrade"
echo "install latest .NET Runtime from feed"
echo "add .NET Runtime bin to path of current command line"
echo "set installed version as default"
echo ""
echo "dotnetsdk install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p -persistent]"
echo "<semver>|<alias> install requested .NET Runtime from feed"
echo "<nupkg> install requested .NET Runtime from local package on filesystem"
echo "latest install latest version of .NET Runtime from feed"
echo "-a|-alias <alias> set alias <alias> for requested .NET Runtime on install"
echo "-p -persistent set installed version as default"
echo "add .NET Runtime bin to path of current command line"
echo ""
echo "dotnetsdk use <semver>|<alias>|<package>|none [-p -persistent]"
echo "<semver>|<alias>|<package> add .NET Runtime bin to path of current command line "
echo "none remove .NET Runtime bin from path of current command line"
echo "-p -persistent set selected version as default"
echo ""
echo "dotnetsdk list"
echo "list .NET Runtime versions installed "
echo ""
echo "dotnetsdk alias"
echo "list .NET Runtime aliases which have been defined"
echo ""
echo "dotnetsdk alias <alias>"
echo "display value of the specified alias"
echo ""
echo "dotnetsdk alias <alias> <semver>|<alias>|<package>"
echo "<alias> the name of the alias to set"
echo "<semver>|<alias>|<package> the .NET Runtime version to set the alias to. Alternatively use the version of the specified alias"
echo ""
echo "dotnetsdk unalias <alias>"
echo "remove the specified alias"
echo ""
;;
"upgrade" )
[ $# -ne 1 ] && dotnetsdk help && return
dotnetsdk install latest -p
;;
"install" )
[ $# -lt 2 ] && dotnetsdk help && return
shift
local persistent=
local versionOrAlias=
local alias=
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
local persistent="-p"
elif [[ $1 == "-a" || $1 == "-alias" ]]; then
local alias=$2
shift
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && dotnetsdk help && return 1
local versionOrAlias=$1
fi
shift
done
if [[ "$versionOrAlias" == "latest" ]]; then
echo "Determining latest version"
versionOrAlias=$(_dotnetsdk_find_latest)
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DOTNET_FEED" && return 1
echo "Latest version is $versionOrAlias"
fi
if [[ "$versionOrAlias" == *.nupkg ]]; then
local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
local runtimeVersion=$(_dotnetsdk_package_version "$runtimeFullName")
local runtimeFolder="$DOTNET_USER_PACKAGES/$runtimeFullName"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
if [ -e "$runtimeFolder" ]; then
echo "$runtimeFullName already installed"
else
mkdir "$runtimeFolder" > /dev/null 2>&1
cp -a "$versionOrAlias" "$runtimeFile"
_dotnetsdk_unpack "$runtimeFile" "$runtimeFolder"
[[ $? == 1 ]] && return 1
fi
dotnetsdk use "$runtimeVersion" "$persistent"
[[ -n $alias ]] && dotnetsdk alias "$alias" "$runtimeVersion"
else
local runtimeFullName="$(_dotnetsdk_requested_version_or_alias $versionOrAlias)"
local runtimeFolder="$DOTNET_USER_PACKAGES/$runtimeFullName"
_dotnetsdk_download "$runtimeFullName" "$runtimeFolder"
[[ $? == 1 ]] && return 1
dotnetsdk use "$versionOrAlias" "$persistent"
[[ -n $alias ]] && dotnetsdk alias "$alias" "$versionOrAlias"
fi
;;
"use" )
[ $# -gt 3 ] && dotnetsdk help && return
[ $# -lt 2 ] && dotnetsdk help && return
shift
local persistent=
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
local persistent="true"
elif [[ -n $1 ]]; then
local versionOrAlias=$1
fi
shift
done
if [[ $versionOrAlias == "none" ]]; then
echo "Removing .NET Runtime from process PATH"
# Strip other version from PATH
PATH=$(_dotnetsdk_strip_path "$PATH" "/bin")
if [[ -n $persistent && -e "$DOTNET_USER_HOME/alias/default.alias" ]]; then
echo "Setting default .NET Runtime to none"
rm "$DOTNET_USER_HOME/alias/default.alias"
fi
return 0
fi
local runtimeFullName=$(_dotnetsdk_requested_version_or_alias "$versionOrAlias")
local runtimeBin=$(_dotnetsdk_locate_runtime_bin_from_full_name "$runtimeFullName")
if [[ -z $runtimeBin ]]; then
echo "Cannot find $runtimeFullName, do you need to run 'dotnetsdk install $versionOrAlias'?"
return 1
fi
echo "Adding" $runtimeBin "to process PATH"
PATH=$(_dotnetsdk_strip_path "$PATH" "/bin")
PATH=$(_dotnetsdk_prepend_path "$PATH" "$runtimeBin")
if [[ -n $persistent ]]; then
local runtimeVersion=$(_dotnetsdk_package_version "$runtimeFullName")
dotnetsdk alias default "$runtimeVersion"
fi
;;
"alias" )
[[ $# -gt 3 ]] && dotnetsdk help && return
[[ ! -e "$DOTNET_USER_HOME/alias/" ]] && mkdir "$DOTNET_USER_HOME/alias/" > /dev/null
if [[ $# == 1 ]]; then
echo ""
local format="%-20s %s\n"
printf "$format" "Alias" "Name"
printf "$format" "-----" "----"
for _dotnetsdk_file in $(find "$DOTNET_USER_HOME/alias" -name *.alias); do
local alias="$(basename $_dotnetsdk_file | sed 's/.alias//')"
local name="$(cat $_dotnetsdk_file)"
printf "$format" "$alias" "$name"
done
echo ""
return
fi
local name="$2"
if [[ $# == 2 ]]; then
[[ ! -e "$DOTNET_USER_HOME/alias/$name.alias" ]] && echo "There is no alias called '$name'" && return
cat "$DOTNET_USER_HOME/alias/$name.alias"
echo ""
return
fi
local runtimeFullName=$(_dotnetsdk_requested_version_or_alias "$3")
[[ ! -d "$DOTNET_USER_PACKAGES/$runtimeFullName" ]] && echo "$runtimeFullName is not an installed .NET Runtime version" && return 1
local action="Setting"
[[ -e "$DOTNET_USER_HOME/alias/$name.alias" ]] && action="Updating"
echo "$action alias '$name' to '$runtimeFullName'"
echo "$runtimeFullName" > "$DOTNET_USER_HOME/alias/$name.alias"
;;
"unalias" )
[[ $# -ne 2 ]] && dotnetsdk help && return
local name=$2
local aliasPath="$DOTNET_USER_HOME/alias/$name.alias"
[[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1
echo "Removing alias $name"
rm "$aliasPath" >> /dev/null 2>&1
;;
"list" )
[[ $# -gt 2 ]] && dotnetsdk help && return
[[ ! -d $DOTNET_USER_PACKAGES ]] && echo ".NET Runtime is not installed." && return 1
local searchGlob="dotnet-*"
if [ $# == 2 ]; then
local versionOrAlias=$2
local searchGlob=$(_dotnetsdk_requested_version_or_alias "$versionOrAlias")
fi
echo ""
# Separate empty array declaration from initialization
# to avoid potential ZSH error: local:217: maximum nested function level reached
local arr
arr=()
# Z shell array-index starts at one.
local i=1
local format="%-20s %s\n"
for _dotnetsdk_file in $(find "$DOTNET_USER_HOME/alias" -name *.alias); do
arr[$i]="$(basename $_dotnetsdk_file | sed 's/.alias//')/$(cat $_dotnetsdk_file)"
let i+=1
done
local formatString="%-6s %-20s %-7s %-20s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Location" "Alias"
printf "$formatString" "------" "-------" "-------" "--------" "-----"
local formattedHome=`(echo $DOTNET_USER_PACKAGES | sed s=$HOME=~=g)`
for f in $(find $DOTNET_USER_PACKAGES -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;); do
local active=""
[[ $PATH == *"$DOTNET_USER_PACKAGES/$f/bin"* ]] && local active=" *"
local pkgName=$(_dotnetsdk_package_runtime "$f")
local pkgVersion=$(_dotnetsdk_package_version "$f")
local alias=""
local delim=""
for i in "${arr[@]}"; do
temp="dotnet-$pkgName.$pkgVersion"
temp2="dotnet-$pkgName-x86.$pkgVersion"
if [[ ${i#*/} == $temp || ${i#*/} == $temp2 ]]; then
alias+="$delim${i%/*}"
delim=", "
fi
done
printf "$formatString" "$active" "$pkgVersion" "$pkgName" "$formattedHome" "$alias"
[[ $# == 2 ]] && echo "" && return 0
done
echo ""
[[ $# == 2 ]] && echo "$versionOrAlias not found" && return 1
;;
*)
echo "Unknown command $1"
return 1
esac
return 0
}
dotnetsdk list default >/dev/null && dotnetsdk use default >/dev/null || true

View File

@ -1,8 +1,8 @@
@Echo off
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0dotnetsdk.ps1' %*"
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0kvm.ps1' %*"
IF EXIST "%USERPROFILE%\.dotnet\temp-set-envvars.cmd" (
CALL "%USERPROFILE%\.dotnet\temp-set-envvars.cmd"
DEL "%USERPROFILE%\.dotnet\temp-set-envvars.cmd"
IF EXIST "%USERPROFILE%\.k\temp-set-envvars.cmd" (
CALL "%USERPROFILE%\.k\temp-set-envvars.cmd"
DEL "%USERPROFILE%\.k\temp-set-envvars.cmd"
)

View File

@ -3,19 +3,14 @@ param(
[string] $Command,
[string] $Proxy,
[switch] $Verbosity = $false,
[alias("g")][switch] $Global = $false,
[alias("p")][switch] $Persistent = $false,
[alias("f")][switch] $Force = $false,
[alias("r")][string] $Runtime,
[alias("arch")][string] $Architecture,
[switch] $X86 = $false,
[switch] $Amd64 = $false,
#deprecated
[switch] $X64 = $false,
#deprecated
[switch] $Svr50 = $false,
#deprecated
[switch] $Svrc50 = $false,
[alias("amd64")][switch] $X64 = $false,
[alias("w")][switch] $Wait = $false,
[alias("a")]
[string] $Alias = $null,
@ -27,29 +22,44 @@ param(
[switch] $AssumeElevated
)
# "Constants" (in as much as PowerShell will allow)
$RuntimePackageName = "dotnet"
$RuntimeFriendlyName = ".NET Runtime"
$RuntimeProgramFilesName = "Microsoft .NET Cross-Platform Runtime"
$RuntimeFolderName = ".dotnet"
$DefaultFeed = "https://www.myget.org/F/aspnetvnext/api/v2"
$CrossGenCommand = "k-crossgen"
# Constants
Set-Variable -Option Constant "BuildNumber" "10308"
Set-Variable -Option Constant "RuntimePackageName" "kre"
Set-Variable -Option Constant "RuntimeFriendlyName" "K Runtime"
Set-Variable -Option Constant "RuntimeShortName" "KRE"
Set-Variable -Option Constant "RuntimeFolderName" ".k"
Set-Variable -Option Constant "CommandName" "kvm"
Set-Variable -Option Constant "VersionManagerName" "K Version Manager"
Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
Set-Variable -Option Constant "CrossGenCommand" "k-crossgen"
Set-Variable -Option Constant "HomeEnvVar" "KRE_HOME"
Set-Variable -Option Constant "UserHomeEnvVar" "KRE_USER_HOME"
Set-Variable -Option Constant "FeedEnvVar" "KRE_FEED"
$selectedArch=$null;
$defaultArch="x86"
$selectedRuntime=$null
$defaultRuntime="clr"
# Get or calculate userDotNetPath
$userDotNetPath = $env:DOTNET_USER_PATH
if(!$userDotNetPath) { $userDotNetPath = $env:USERPROFILE + "\$RuntimeFolderName" }
$userDotNetRuntimesPath = $userDotNetPath + "\runtimes"
function getenv($name) {
if(Test-Path "env:\$name") {
cat "env:\$name"
}
}
# Get or calculate globalDotNetPath
$globalDotNetPath = $env:DOTNET_GLOBAL_PATH
if(!$globalDotNetPath) { $globalDotNetPath = $env:ProgramFiles + "\$RuntimeProgramFilesName" }
$globalDotNetRuntimesPath = $globalDotNetPath + "\runtimes"
$feed = $env:DOTNET_FEED
# Get or calculate userHome
$userHome = (getenv $UserHomeEnvVar)
if(!$userHome) { $userHome = $env:USERPROFILE + "\$RuntimeFolderName" }
$userRuntimesPath = $userHome + "\runtimes"
# Get the feed from the environment variable or set it to the default value
$feed = (getenv $FeedEnvVar)
if (!$feed)
{
$feed = $DefaultFeed;
}
$feed = $feed.TrimEnd("/")
# In some environments, like Azure Websites, the Write-* cmdlets don't work
$useHostOutputMethods = $true
@ -58,122 +68,116 @@ function String-IsEmptyOrWhitespace([string]$str) {
return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0
}
if (!$feed)
{
$feed = $DefaultFeed;
}
$feed = $feed.TrimEnd("/")
$scriptPath = $myInvocation.MyCommand.Definition
function DotNetSdk-Help {
function _Help {
@"
.NET SDK Manager - Build 10206
$VersionManagerName - Build $BuildNumber
USAGE: dotnetsdk <command> [options]
USAGE: $CommandName <command> [options]
dotnetsdk upgrade [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-g|-Global] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
install latest .NET Runtime from feed
$CommandName upgrade [-X86|-X64] [-r|-Runtime CLR|CoreCLR] [-g|-Global] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
install latest $RuntimeShortName from feed
set 'default' alias to installed version
add KRE bin to user PATH environment variable
add $RuntimeShortName bin to user PATH environment variable
-g|-Global install to machine-wide location
-f|-Force upgrade even if latest is already installed
-Proxy <ADDRESS> use given address as proxy when accessing remote server (e.g. https://username:password@proxyserver:8080/). Alternatively set proxy using http_proxy environment variable.
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
dotnetsdk install <semver>|<alias>|<nupkg>|latest [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-a|-Alias <alias>] [-g|-Global] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
<semver>|<alias> install requested .NET Runtime from feed
<nupkg> install requested .NET Runtime from package on local filesystem
latest install latest .NET Runtime from feed
add .NET Runtime bin to path of current command line
-p|-Persistent add .NET Runtime bin to PATH environment variables persistently
-a|-Alias <alias> set alias <alias> for requested .NET Runtime on install
-g|-Global install to machine-wide location
$CommandName install <semver>|<alias>|<nupkg>|latest [-X86|-X64] [-r|-Runtime CLR|CoreCLR] [-a|-Alias <alias>] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
<semver>|<alias> install requested $RuntimeShortName from feed
<nupkg> install requested $RuntimeShortName from package on local filesystem
latest install latest $RuntimeShortName from feed
add $RuntimeShortName bin to path of current command line
-p|-Persistent add $RuntimeShortName bin to PATH environment variables persistently
-a|-Alias <alias> set alias <alias> for requested $RuntimeShortName on install
-f|-Force install even if specified version is already installed
-Proxy <ADDRESS> use given address as proxy when accessing remote server (e.g. https://username:password@proxyserver:8080/). Alternatively set proxy using http_proxy environment variable.
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
dotnetsdk use <semver>|<alias>|<package>|none [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-p|-Persistent] [-g|-Global]
<semver>|<alias>|<package> add .NET Runtime bin to path of current command line
none remove .NET Runtime bin from path of current command line
-p|-Persistent add .NET Runtime bin to PATH environment variables persistently
-g|-Global combined with -p to change machine PATH instead of user PATH
$CommandName use <semver>|<alias>|<package>|none [-X86|-X64] [-r|-Runtime CLR|CoreCLR] [-p|-Persistent]
<semver>|<alias>|<package> add $RuntimeShortName bin to path of current command line
none remove $RuntimeShortName bin from path of current command line
-p|-Persistent add $RuntimeShortName bin to PATH environment variable across all processes run by the current user
dotnetsdk list
list .NET Runtime versions installed
$CommandName list
list $RuntimeShortName versions installed
dotnetsdk alias
list .NET Runtime aliases which have been defined
$CommandName alias
list $RuntimeShortName aliases which have been defined
dotnetsdk alias <alias>
$CommandName alias <alias>
display value of the specified alias
dotnetsdk alias <alias> <semver>|<alias>|<package> [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR]
$CommandName alias <alias> <semver>|<alias>|<package> [-X86|-X64] [-r|-Runtime CLR|CoreCLR]
<alias> the name of the alias to set
<semver>|<alias>|<package> the .NET Runtime version to set the alias to. Alternatively use the version of the specified alias
<semver>|<alias>|<package> the $RuntimeShortName version to set the alias to. Alternatively use the version of the specified alias
dotnetsdk unalias <alias>
$CommandName unalias <alias>
remove the specified alias
"@ -replace "`n","`r`n" | Console-Write
}
function DotNetSdk-Global-Setup {
$dotnetsdkBinPath = "$userDotNetPath\bin"
function _Global-Setup {
# Sets up the version manager tool and adds the user-local runtime install directory to the home variable
# Note: We no longer do global install via this tool. The MSI handles global install of runtimes AND will set
# the machine level home value.
# In this configuration, the user-level path will OVERRIDE the global path because it is placed first.
$cmdBinPath = "$userHome\bin"
If (Needs-Elevation)
{
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -global -wait"
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Console-Write "Adding $dotnetsdkBinPath to process PATH"
Set-Path (Change-Path $env:Path $dotnetsdkBinPath ($dotnetsdkBinPath))
Console-Write "Adding $globalDotNetPath;%USERPROFILE%\$RuntimeFolderName to process DOTNET_HOME"
$envDotNetHome = $env:DOTNET_HOME
$envDotNetHome = Change-Path $envDotNetHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
$envDotNetHome = Change-Path $envDotNetHome $globalDotNetPath ($globalDotNetPath)
$env:DOTNET_HOME = $envDotNetHome
Console-Write "Adding $cmdBinPath to process PATH"
Set-Path (Change-Path $env:Path $cmdBinPath ($cmdBinPath))
Console-Write "Adding %USERPROFILE%\$RuntimeFolderName to process $HomeEnvVar"
$envRuntimeHome = (getenv $HomeEnvVar)
$envRuntimeHome = Change-Path $envRuntimeHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
Set-Content "env:\$HomeEnvVar" $envRuntimeHome
Console-Write "Setup complete"
break
}
$scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath)
Console-Write "Copying file $dotnetsdkBinPath\dotnetsdk.ps1"
md $dotnetsdkBinPath -Force | Out-Null
copy "$scriptFolder\dotnetsdk.ps1" "$dotnetsdkBinPath\dotnetsdk.ps1"
Console-Write "Copying file $cmdBinPath\$CommandName.ps1"
md $cmdBinPath -Force | Out-Null
copy "$scriptFolder\$CommandName.ps1" "$cmdBinPath\$CommandName.ps1"
Console-Write "Copying file $dotnetsdkBinPath\dotnetsdk.cmd"
copy "$scriptFolder\dotnetsdk.cmd" "$dotnetsdkBinPath\dotnetsdk.cmd"
Console-Write "Copying file $cmdBinPath\$CommandName.cmd"
copy "$scriptFolder\$CommandName.cmd" "$cmdBinPath\$CommandName.cmd"
Console-Write "Adding $dotnetsdkBinPath to process PATH"
Set-Path (Change-Path $env:Path $dotnetsdkBinPath ($dotnetsdkBinPath))
Console-Write "Adding $cmdBinPath to process PATH"
Set-Path (Change-Path $env:Path $cmdBinPath ($cmdBinPath))
Console-Write "Adding $dotnetsdkBinPath to user PATH"
Console-Write "Adding $cmdBinPath to user PATH"
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
$userPath = Change-Path $userPath $dotnetsdkBinPath ($dotnetsdkBinPath)
$userPath = Change-Path $userPath $cmdBinPath ($cmdBinPath)
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
Console-Write "Adding $globalDotNetPath;%USERPROFILE%\$RuntimeFolderName to process DOTNET_HOME"
$envDotNetHome = $env:DOTNET_HOME
$envDotNetHome = Change-Path $envDotNetHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
$envDotNetHome = Change-Path $envDotNetHome $globalDotNetPath ($globalDotNetPath)
$env:DOTNET_HOME = $envDotNetHome
Console-Write "Adding %USERPROFILE%\$RuntimeFolderName to process $HomeEnvVar"
$envRuntimeHome = (getenv $HomeEnvVar)
$envRuntimeHome = Change-Path $envRuntimeHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
Set-Content "env:\$HomeEnvVar" $envRuntimeHome
Console-Write "Adding $globalDotNetPath;%USERPROFILE%\$RuntimeFolderName to machine DOTNET_HOME"
$machineDotNetHome = [Environment]::GetEnvironmentVariable("DOTNET_HOME", [System.EnvironmentVariableTarget]::Machine)
$machineDotNetHome = Change-Path $machineDotNetHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
$machineDotNetHome = Change-Path $machineDotNetHome $globalDotNetPath ($globalDotNetPath)
[Environment]::SetEnvironmentVariable("DOTNET_HOME", $machineDotNetHome, [System.EnvironmentVariableTarget]::Machine)
Console-Write "Adding %USERPROFILE%\$RuntimeFolderName to machine $HomeEnvVar"
$machineruntimeHome = [Environment]::GetEnvironmentVariable($HomeEnvVar, [System.EnvironmentVariableTarget]::Machine)
$machineruntimeHome = Change-Path $machineruntimeHome "%USERPROFILE%\$RuntimeFolderName" ("%USERPROFILE%\$RuntimeFolderName")
[Environment]::SetEnvironmentVariable($HomeEnvVar, $machineruntimeHome, [System.EnvironmentVariableTarget]::Machine)
}
function DotNetSdk-Upgrade {
function _Upgrade {
param(
[boolean] $isGlobal
)
$Persistent = $true
$Alias="default"
DotNetSdk-Install "latest" $isGlobal
_Install "latest" $isGlobal
}
function Add-Proxy-If-Specified {
@ -195,7 +199,7 @@ param(
}
}
function DotNetSdk-Find-Latest {
function _Find-Latest {
param(
[string] $platform,
[string] $architecture
@ -206,6 +210,7 @@ param(
$wc = New-Object System.Net.WebClient
Add-Proxy-If-Specified($wc)
Write-Verbose "Downloading $url ..."
[xml]$xml = $wc.DownloadString($url)
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
@ -217,7 +222,7 @@ param(
return $version
}
function Do-DotNetSdk-Download {
function Do-Download {
param(
[string] $runtimeFullName,
[string] $runtimesFolder
@ -252,9 +257,10 @@ param(
$wc = New-Object System.Net.WebClient
Add-Proxy-If-Specified($wc)
Write-Verbose "Downloading $url ..."
$wc.DownloadFile($url, $tempDownloadFile)
Do-DotNetSdk-Unpack $tempDownloadFile $runtimeTempDownload
Do-Unpack $tempDownloadFile $runtimeTempDownload
md $runtimeFolder -Force | Out-Null
Console-Write "Installing to $runtimeFolder"
@ -262,7 +268,7 @@ param(
Remove-Item "$runtimeTempDownload" -Force | Out-Null
}
function Do-DotNetSdk-Unpack {
function Do-Unpack {
param(
[string] $runtimeFile,
[string] $runtimeFolder
@ -299,15 +305,18 @@ param(
If (Test-Path ($runtimeFolder + "\package\")) {
Remove-Item ($runtimeFolder + "\package\") -Force -Recurse
}
# Clean up the package file itself.
Remove-Item $runtimeFile -Force
}
function DotNetSdk-Install {
function _Install {
param(
[string] $versionOrAlias,
[boolean] $isGlobal
)
if ($versionOrAlias -eq "latest") {
$versionOrAlias = DotNetSdk-Find-Latest (Requested-Platform $defaultRuntime) (Requested-Architecture $defaultArch)
$versionOrAlias = _Find-Latest (Requested-Platform $defaultRuntime) (Requested-Architecture $defaultArch)
}
if ($versionOrAlias.EndsWith(".nupkg")) {
@ -316,17 +325,7 @@ param(
$runtimeFullName = Requested-VersionOrAlias $versionOrAlias
}
if ($isGlobal) {
if (Needs-Elevation) {
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' install '$versionOrAlias' -global $(Requested-Switches) -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
DotNetSdk-Use $runtimeFullName
break
}
$packageFolder = $globalDotNetRuntimesPath
} else {
$packageFolder = $userDotNetRuntimesPath
}
$packageFolder = $userRuntimesPath
if ($versionOrAlias.EndsWith(".nupkg")) {
Set-Variable -Name "selectedArch" -Value (Package-Arch $runtimeFullName) -Scope Script
@ -353,7 +352,7 @@ param(
}
copy $versionOrAlias $tempDownloadFile
Do-DotNetSdk-Unpack $tempDownloadFile $tempUnpackFolder
Do-Unpack $tempDownloadFile $tempUnpackFolder
md $runtimeFolder -Force | Out-Null
Console-Write "Installing to $runtimeFolder"
mv "$tempUnpackFolder\*" $runtimeFolder
@ -362,17 +361,17 @@ param(
$packageVersion = Package-Version $runtimeFullName
DotNetSdk-Use $packageVersion
_Use $packageVersion
if (!$(String-IsEmptyOrWhitespace($Alias))) {
DotNetSdk-Alias-Set $Alias $packageVersion
_Alias-Set $Alias $packageVersion
}
}
else
{
Do-DotNetSdk-Download $runtimeFullName $packageFolder
DotNetSdk-Use $versionOrAlias
Do-Download $runtimeFullName $packageFolder
_Use $versionOrAlias
if (!$(String-IsEmptyOrWhitespace($Alias))) {
DotNetSdk-Alias-Set "$Alias" $versionOrAlias
_Alias-Set "$Alias" $versionOrAlias
}
}
@ -388,20 +387,20 @@ param(
}
}
function DotNetSdk-List {
$dotnetHome = $env:DOTNET_HOME
if (!$dotnetHome) {
$dotnetHome = "$globalDotNetPath;$userDotNetPath"
function _List {
$runtimeHome = (getenv $HomeEnvVar)
if (!$runtimeHome) {
$runtimeHome = "$userHome"
}
md ($userDotNetPath + "\alias\") -Force | Out-Null
$aliases = Get-ChildItem ($userDotNetPath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }}
md ($userHome + "\alias\") -Force | Out-Null
$aliases = Get-ChildItem ($userHome + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }}
$items = @()
foreach($portion in $dotnetHome.Split(';')) {
foreach($portion in $runtimeHome.Split(';')) {
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
if (Test-Path("$path\runtimes")) {
$items += Get-ChildItem ("$path\runtimes\dotnet-*") | List-Parts $aliases
$items += Get-ChildItem ("$path\runtimes\$RuntimePackageName-*") | List-Parts $aliases
}
}
@ -448,59 +447,20 @@ filter List-Parts {
}
}
function DotNetSdk-Global-Use {
param(
[string] $versionOrAlias
)
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
If (Needs-Elevation) {
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' use '$versionOrAlias' -global $(Requested-Switches) -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
DotNetSdk-Use $versionOrAlias
break
}
DotNetSdk-Use "$versionOrAlias"
if ($versionOrAlias -eq "none") {
if ($Persistent) {
Console-Write "Removing .NET Runtime from machine PATH"
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$machinePath = Change-Path $machinePath "" ($globalDotNetRuntimesPath, $userDotNetRuntimesPath)
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
}
return;
}
$runtimeFullName = Requested-VersionOrAlias "$versionOrAlias"
$runtimeBin = Locate-DotNetBinFromFullName $runtimeFullName
if ($runtimeBin -eq $null) {
throw "Cannot find $runtimeFullName, do you need to run 'dotnetsdk install $versionOrAlias'?"
}
if ($Persistent) {
Console-Write "Adding $runtimeBin to machine PATH"
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$machinePath = Change-Path $machinePath $runtimeBin ($globalDotNetRuntimesPath, $userDotNetRuntimesPath)
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
}
}
function DotNetSdk-Use {
function _Use {
param(
[string] $versionOrAlias
)
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
if ($versionOrAlias -eq "none") {
Console-Write "Removing .NET Runtime from process PATH"
Set-Path (Change-Path $env:Path "" ($globalDotNetRuntimesPath, $userDotNetRuntimesPath))
Console-Write "Removing $RuntimeShortName from process PATH"
Set-Path (Change-Path $env:Path "" ($userRuntimesPath))
if ($Persistent) {
Console-Write "Removing .NET Runtime from user PATH"
Console-Write "Removing $RuntimeShortName from user PATH"
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
$userPath = Change-Path $userPath "" ($globalDotNetRuntimesPath, $userDotNetRuntimesPath)
$userPath = Change-Path $userPath "" ($userRuntimesPath)
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
}
return;
@ -508,61 +468,61 @@ param(
$runtimeFullName = Requested-VersionOrAlias $versionOrAlias
$runtimeBin = Locate-DotNetBinFromFullName $runtimeFullName
$runtimeBin = Locate-RuntimeBinFromFullName $runtimeFullName
if ($runtimeBin -eq $null) {
throw "Cannot find $runtimeFullName, do you need to run 'dotnetsdk install $versionOrAlias'?"
throw "Cannot find $runtimeFullName, do you need to run '$CommandName install $versionOrAlias'?"
}
Console-Write "Adding $runtimeBin to process PATH"
Set-Path (Change-Path $env:Path $runtimeBin ($globalDotNetRuntimesPath, $userDotNetRuntimesPath))
Set-Path (Change-Path $env:Path $runtimeBin ($userRuntimesPath))
if ($Persistent) {
Console-Write "Adding $runtimeBin to user PATH"
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
$userPath = Change-Path $userPath $runtimeBin ($globalDotNetRuntimesPath, $userDotNetRuntimesPath)
$userPath = Change-Path $userPath $runtimeBin ($userRuntimesPath)
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
}
}
function DotNetSdk-Alias-List {
md ($userDotNetPath + "\alias\") -Force | Out-Null
function _Alias-List {
md ($userHome + "\alias\") -Force | Out-Null
Get-ChildItem ($userDotNetPath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
Get-ChildItem ($userHome + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
}
function DotNetSdk-Alias-Get {
function _Alias-Get {
param(
[string] $name
)
md ($userDotNetPath + "\alias\") -Force | Out-Null
$aliasFilePath=$userDotNetPath + "\alias\" + $name + ".txt"
md ($userHome + "\alias\") -Force | Out-Null
$aliasFilePath=$userHome + "\alias\" + $name + ".txt"
if (!(Test-Path $aliasFilePath)) {
Console-Write "Alias '$name' does not exist"
$script:exitCode = 1 # Return non-zero exit code for scripting
} else {
$aliasValue = (Get-Content ($userDotNetPath + "\alias\" + $name + ".txt"))
$aliasValue = (Get-Content ($userHome + "\alias\" + $name + ".txt"))
Console-Write "Alias '$name' is set to $aliasValue"
}
}
function DotNetSdk-Alias-Set {
function _Alias-Set {
param(
[string] $name,
[string] $value
)
$runtimeFullName = Requested-VersionOrAlias $value
$aliasFilePath = $userDotNetPath + "\alias\" + $name + ".txt"
$aliasFilePath = $userHome + "\alias\" + $name + ".txt"
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
Console-Write "$action alias '$name' to '$runtimeFullName'"
md ($userDotNetPath + "\alias\") -Force | Out-Null
md ($userHome + "\alias\") -Force | Out-Null
$runtimeFullName | Out-File ($aliasFilePath) ascii
}
function DotNetSdk-Unalias {
function _Unalias {
param(
[string] $name
)
$aliasPath=$userDotNetPath + "\alias\" + $name + ".txt"
$aliasPath=$userHome + "\alias\" + $name + ".txt"
if (Test-Path -literalPath "$aliasPath") {
Console-Write "Removing alias $name"
Remove-Item -literalPath $aliasPath
@ -572,15 +532,15 @@ param(
}
}
function Locate-DotNetBinFromFullName() {
function Locate-RuntimeBinFromFullName() {
param(
[string] $runtimeFullName
)
$dotnetHome = $env:DOTNET_HOME
if (!$dotnetHome) {
$dotnetHome = "$globalDotNetPath;$userDotNetPath"
$runtimeHome = (getenv $HomeEnvVar)
if (!$runtimeHome) {
$runtimeHome = $userHome
}
foreach($portion in $dotnetHome.Split(';')) {
foreach($portion in $runtimeHome.Split(';')) {
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
$runtimeBin = "$path\runtimes\$runtimeFullName\bin"
if (Test-Path "$runtimeBin") {
@ -601,14 +561,14 @@ function Package-Platform() {
param(
[string] $runtimeFullName
)
return $runtimeFullName -replace 'dotnet-([^-]*).*', '$1'
return $runtimeFullName -replace "$RuntimePackageName-([^-]*).*", '$1'
}
function Package-Arch() {
param(
[string] $runtimeFullName
)
return $runtimeFullName -replace 'dotnet-[^-]*-[^-]*-([^.]*).*', '$1'
return $runtimeFullName -replace "$RuntimePackageName-[^-]*-[^-]*-([^.]*).*", '$1'
}
@ -618,19 +578,19 @@ param(
)
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
$runtimeBin = Locate-DotNetBinFromFullName $versionOrAlias
$runtimeBin = Locate-RuntimeBinFromFullName $versionOrAlias
# If the name specified is an existing package, just use it as is
if ($runtimeBin -ne $null) {
return $versionOrAlias
}
If (Test-Path ($userDotNetPath + "\alias\" + $versionOrAlias + ".txt")) {
$aliasValue = Get-Content ($userDotNetPath + "\alias\" + $versionOrAlias + ".txt")
# Split dotnet-coreclr-win-x86.1.0.0-beta3-10922 into version and name sections
If (Test-Path ($userHome + "\alias\" + $versionOrAlias + ".txt")) {
$aliasValue = Get-Content ($userHome + "\alias\" + $versionOrAlias + ".txt")
# Split runtime-coreclr-win-x86.1.0.0-beta3-10922 into version and name sections
$parts = $aliasValue.Split('.', 2)
$pkgVersion = $parts[1]
# dotnet-coreclr-win-x86
# runtime-coreclr-win-x86
$parts = $parts[0].Split('-', 4)
$pkgPlatform = Requested-Platform $parts[1]
$pkgArchitecture = Requested-Architecture $parts[3]
@ -668,7 +628,7 @@ param(
foreach($portion in $existingPaths.Split(';')) {
$skip = $portion -eq ""
foreach($removePath in $removePaths) {
if ($portion.StartsWith($removePath)) {
if ($removePath -and ($portion.StartsWith($removePath))) {
$skip = $true
}
}
@ -683,11 +643,11 @@ function Set-Path() {
param(
[string] $newPath
)
md $userDotNetPath -Force | Out-Null
md $userHome -Force | Out-Null
$env:Path = $newPath
@"
SET "PATH=$newPath"
"@ | Out-File ($userDotNetPath + "\temp-set-envvars.cmd") ascii
"@ | Out-File ($userHome + "\temp-set-envvars.cmd") ascii
}
function Needs-Elevation() {
@ -703,8 +663,6 @@ function Needs-Elevation() {
function Requested-Switches() {
$arguments = ""
if ($X86) {$arguments = "$arguments -x86"}
if ($Amd64) {$arguments = "$arguments -amd64"}
#deprecated
if ($X64) {$arguments = "$arguments -x64"}
if ($selectedRuntime) {$arguments = "$arguments -runtime $selectedRuntime"}
if ($Persistent) {$arguments = "$arguments -persistent"}
@ -715,37 +673,24 @@ function Requested-Switches() {
function Validate-And-Santitize-Switches()
{
if ($Svr50 -and $Runtime) {throw "You cannot select both the -runtime switch and the -svr50 runtimes"}
if ($Svrc50 -and $Runtime) {throw "You cannot select both the -runtime switch and the -svrc50 runtimes"}
if ($X86 -and $Amd64) {throw "You cannot select both x86 and amd64 architectures"}
if ($X86 -and $X64) {throw "You cannot select both x86 and x64 architectures"}
if ($X64 -and $Amd64) {throw "You cannot select both x64 and amd64 architectures"}
if ($Runtime) {
$validRuntimes = "CoreCLR", "CLR", "svr50", "svrc50"
$validRuntimes = "CoreCLR", "CLR"
$match = $validRuntimes | ? { $_ -like $Runtime } | Select -First 1
if (!$match) {throw "'$runtime' is not a valid runtime"}
Set-Variable -Name "selectedRuntime" -Value $match.ToLowerInvariant() -Scope Script
} elseif ($Svr50) {
Console-Write "Warning: -svr50 is deprecated, use -runtime CLR for new packages."
Set-Variable -Name "selectedRuntime" -Value "svr50" -Scope Script
} elseif ($Svrc50) {
Console-Write "Warning: -svrc50 is deprecated, use -runtime CoreCLR for new packages."
Set-Variable -Name "selectedRuntime" -Value "svrc50" -Scope Script
}
if($Architecture) {
$validArchitectures = "amd64", "x86"
$validArchitectures = "x64", "x86"
$match = $validArchitectures | ? { $_ -like $Architecture } | Select -First 1
if(!$match) {throw "'$architecture' is not a valid architecture"}
Set-Variable -Name "selectedArch" -Value $match.ToLowerInvariant() -Scope Script
}
else {
if ($X64) {
Console-Write "Warning: -x64 is deprecated, use -amd64 for new packages."
Set-Variable -Name "selectedArch" -Value "x64" -Scope Script
} elseif ($Amd64) {
Set-Variable -Name "selectedArch" -Value "amd64" -Scope Script
} elseif ($X86) {
Set-Variable -Name "selectedArch" -Value "x86" -Scope Script
}
@ -801,45 +746,35 @@ param(
function Validate-Full-Package-Name-Arguments-Combination() {
param(
[string] $versionOrAlias
[string] $versionOrAlias
)
if ($versionOrAlias -like "dotnet-*" -and
($selectedArch -or $selectedRuntime)) {
throw "Runtime or architecture cannot be specified when using the full package name."
if ($versionOrAlias -like "$RuntimePackageName-*" -and
($selectedArch -or $selectedRuntime)) {
throw "Runtime or architecture cannot be specified when using the full package name."
}
}
$script:exitCode = 0
try {
Validate-And-Santitize-Switches
if ($Global) {
switch -wildcard ($Command + " " + $Args.Count) {
"setup 0" {DotNetSdk-Global-Setup}
"upgrade 0" {DotNetSdk-Upgrade $true}
"install 1" {DotNetSdk-Install $Args[0] $true}
"use 1" {DotNetSdk-Global-Use $Args[0]}
default {throw "Unknown command, or global switch not supported"};
}
} else {
switch -wildcard ($Command + " " + $Args.Count) {
"setup 0" {DotNetSdk-Global-Setup}
"upgrade 0" {DotNetSdk-Upgrade $false}
"install 1" {DotNetSdk-Install $Args[0] $false}
"list 0" {DotNetSdk-List}
"use 1" {DotNetSdk-Use $Args[0]}
"alias 0" {DotNetSdk-Alias-List}
"alias 1" {DotNetSdk-Alias-Get $Args[0]}
"alias 2" {DotNetSdk-Alias-Set $Args[0] $Args[1]}
"unalias 1" {DotNetSdk-Unalias $Args[0]}
"help 0" {DotNetSdk-Help}
" 0" {DotNetSdk-Help}
default {throw "Unknown command"};
}
switch -wildcard ($Command + " " + $Args.Count) {
"setup 0" {_Global-Setup}
"upgrade 0" {_Upgrade $false}
"install 1" {_Install $Args[0] $false}
"list 0" {_List}
"use 1" {_Use $Args[0]}
"alias 0" {_Alias-List}
"alias 1" {_Alias-Get $Args[0]}
"alias 2" {_Alias-Set $Args[0] $Args[1]}
"unalias 1" {_Unalias $Args[0]}
"help 0" {_Help}
" 0" {_Help}
default {throw "Unknown command"};
}
}
catch {
Console-Write-Error $_
Console-Write "Type 'dotnetsdk help' for help on how to use dotnetsdk."
Console-Write "Type '$CommandName help' for help on how to use $CommandName."
$script:exitCode = -1
}
if ($Wait) {

432
build/kvm.sh Normal file
View File

@ -0,0 +1,432 @@
# kvm.sh
# Source this file from your .bash-profile or script to use
# "Constants"
_KVM_BUILDNUMBER="10308"
_KVM_RUNTIME_PACKAGE_NAME="kre"
_KVM_RUNTIME_FRIENDLY_NAME="K Runtime"
_KVM_RUNTIME_SHORT_NAME="KRE"
_KVM_RUNTIME_FOLDER_NAME=".k"
_KVM_COMMAND_NAME="kvm"
_KVM_VERSION_MANAGER_NAME="K Version Manager"
_KVM_DEFAULT_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
_KVM_HOME_VAR_NAME="KRE_HOME"
__kvm_has() {
type "$1" > /dev/null 2>&1
return $?
}
if __kvm_has "unsetopt"; then
unsetopt nomatch 2>/dev/null
fi
if [ -z "$KVM_USER_HOME" ]; then
eval KVM_USER_HOME="~/$K_DIR_NAME"
fi
_KVM_USER_PACKAGES="$KVM_USER_HOME/runtimes"
_KVM_ALIAS_DIR="$KVM_USER_HOME/alias"
if [ -z "$KRE_FEED" ]; then
KRE_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
fi
__kvm_find_latest() {
local platform="mono"
if ! __kvm_has "curl"; then
echo "$_KVM_COMMAND_NAME needs curl to proceed." >&2;
return 1
fi
local url="$KRE_FEED/GetUpdates()?packageIds=%27$_KVM_RUNTIME_PACKAGE_NAME-$platform%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
xml="$(curl $url 2>/dev/null)"
echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1
version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')"
echo $version
}
__kvm_strip_path() {
echo "$1" | sed -e "s#$_KVM_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_KVM_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_KVM_USER_PACKAGES/[^/]*$2[^:]*##g"
}
__kvm_prepend_path() {
if [ -z "$1" ]; then
echo "$2"
else
echo "$2:$1"
fi
}
__kvm_package_version() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/[^.]*.\(.*\)/\1/"
}
__kvm_package_name() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/\([^.]*\).*/\1/"
}
__kvm_package_runtime() {
local runtimeFullName="$1"
echo "$runtimeFullName" | sed "s/$_KVM_RUNTIME_PACKAGE_NAME-\([^.-]*\).*/\1/"
}
__kvm_download() {
local runtimeFullName="$1"
local runtimeFolder="$2"
local pkgName=$(__kvm_package_name "$runtimeFullName")
local pkgVersion=$(__kvm_package_version "$runtimeFullName")
local url="$KRE_FEED/package/$pkgName/$pkgVersion"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
if [ -e "$runtimeFolder" ]; then
echo "$runtimeFullName already installed."
return 0
fi
echo "Downloading $runtimeFullName from $KRE_FEED"
if ! __kvm_has "curl"; then
echo "$_KVM_COMMAND_NAME needs curl to proceed." >&2;
return 1
fi
mkdir -p "$runtimeFolder" > /dev/null 2>&1
local httpResult=$(curl -L -D - "$url" -o "$runtimeFile" 2>/dev/null | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
[[ $httpResult == "404" ]] && echo "$runtimeFullName was not found in repository $KRE_FEED" && return 1
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $runtimeFullName from $KRE_FEED" && return 1
__kvm_unpack $runtimeFile $runtimeFolder
return $?
}
__kvm_unpack() {
local runtimeFile="$1"
local runtimeFolder="$2"
echo "Installing to $runtimeFolder"
if ! __kvm_has "unzip"; then
echo "$_KVM_COMMAND_NAME needs unzip to proceed." >&2;
return 1
fi
unzip $runtimeFile -d $runtimeFolder > /dev/null 2>&1
[ -e "$runtimeFolder/[Content_Types].xml" ] && rm "$runtimeFolder/[Content_Types].xml"
[ -e "$runtimeFolder/_rels/" ] && rm -rf "$runtimeFolder/_rels/"
[ -e "$runtimeFolder/package/" ] && rm -rf "$runtimeFolder/_package/"
[ -e "$runtimeFile" ] && rm -f "$runtimeFile"
#Set shell commands as executable
find "$runtimeFolder/bin/" -type f \
-exec sh -c "head -c 11 {} | grep '/bin/bash' > /dev/null" \; -print | xargs chmod 775
}
__kvm_requested_version_or_alias() {
local versionOrAlias="$1"
local runtimeBin=$(__kvm_locate_runtime_bin_from_full_name "$versionOrAlias")
# If the name specified is an existing package, just use it as is
if [ -n "$runtimeBin" ]; then
echo "$versionOrAlias"
else
if [ -e "$_KVM_ALIAS_DIR/$versionOrAlias.alias" ]; then
local runtimeFullName=$(cat "$_KVM_ALIAS_DIR/$versionOrAlias.alias")
local pkgName=$(echo $runtimeFullName | sed "s/\([^.]*\).*/\1/")
local pkgVersion=$(echo $runtimeFullName | sed "s/[^.]*.\(.*\)/\1/")
local pkgPlatform=$(echo "$pkgName" | sed "s/kre-\([^.-]*\).*/\1/")
else
local pkgVersion=$versionOrAlias
local pkgPlatform="mono"
fi
echo "$_KVM_RUNTIME_PACKAGE_NAME-$pkgPlatform.$pkgVersion"
fi
}
# This will be more relevant if we support global installs
__kvm_locate_runtime_bin_from_full_name() {
local runtimeFullName=$1
[ -e "$_KVM_USER_PACKAGES/$runtimeFullName/bin" ] && echo "$_KVM_USER_PACKAGES/$runtimeFullName/bin" && return
}
kvm()
{
if [ $# -lt 1 ]; then
$_KVM_COMMAND_NAME help
return
fi
case $1 in
"help" )
echo ""
echo "$_KVM_VERSION_MANAGER_NAME - Build $_KVM_BUILDNUMBER"
echo ""
echo "USAGE: $_KVM_COMMAND_NAME <command> [options]"
echo ""
echo "$_KVM_COMMAND_NAME upgrade"
echo "install latest $_KVM_RUNTIME_SHORT_NAME from feed"
echo "add $_KVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo "set installed version as default"
echo ""
echo "$_KVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p -persistent]"
echo "<semver>|<alias> install requested $_KVM_RUNTIME_SHORT_NAME from feed"
echo "<nupkg> install requested $_KVM_RUNTIME_SHORT_NAME from local package on filesystem"
echo "latest install latest version of $_KVM_RUNTIME_SHORT_NAME from feed"
echo "-a|-alias <alias> set alias <alias> for requested $_KVM_RUNTIME_SHORT_NAME on install"
echo "-p -persistent set installed version as default"
echo "add $_KVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo ""
echo "$_KVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p -persistent]"
echo "<semver>|<alias>|<package> add $_KVM_RUNTIME_SHORT_NAME bin to path of current command line "
echo "none remove $_KVM_RUNTIME_SHORT_NAME bin from path of current command line"
echo "-p -persistent set selected version as default"
echo ""
echo "$_KVM_COMMAND_NAME list"
echo "list $_KVM_RUNTIME_SHORT_NAME versions installed "
echo ""
echo "$_KVM_COMMAND_NAME alias"
echo "list $_KVM_RUNTIME_SHORT_NAME aliases which have been defined"
echo ""
echo "$_KVM_COMMAND_NAME alias <alias>"
echo "display value of the specified alias"
echo ""
echo "$_KVM_COMMAND_NAME alias <alias> <semver>|<alias>|<package>"
echo "<alias> the name of the alias to set"
echo "<semver>|<alias>|<package> the $_KVM_RUNTIME_SHORT_NAME version to set the alias to. Alternatively use the version of the specified alias"
echo ""
echo "$_KVM_COMMAND_NAME unalias <alias>"
echo "remove the specified alias"
echo ""
;;
"upgrade" )
[ $# -ne 1 ] && kvm help && return
$_KVM_COMMAND_NAME install latest -p
;;
"install" )
[ $# -lt 2 ] && kvm help && return
shift
local persistent=
local versionOrAlias=
local alias=
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
local persistent="-p"
elif [[ $1 == "-a" || $1 == "-alias" ]]; then
local alias=$2
shift
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && kvm help && return 1
local versionOrAlias=$1
fi
shift
done
if [[ "$versionOrAlias" == "latest" ]]; then
echo "Determining latest version"
versionOrAlias=$(__kvm_find_latest)
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $KRE_FEED" && return 1
echo "Latest version is $versionOrAlias"
fi
if [[ "$versionOrAlias" == *.nupkg ]]; then
local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
local runtimeVersion=$(__kvm_package_version "$runtimeFullName")
local runtimeFolder="$_KVM_USER_PACKAGES/$runtimeFullName"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
if [ -e "$runtimeFolder" ]; then
echo "$runtimeFullName already installed"
else
mkdir "$runtimeFolder" > /dev/null 2>&1
cp -a "$versionOrAlias" "$runtimeFile"
__kvm_unpack "$runtimeFile" "$runtimeFolder"
[[ $? == 1 ]] && return 1
fi
$_KVM_COMMAND_NAME use "$runtimeVersion" "$persistent"
[[ -n $alias ]] && kvm alias "$alias" "$runtimeVersion"
else
local runtimeFullName="$(__kvm_requested_version_or_alias $versionOrAlias)"
local runtimeFolder="$_KVM_USER_PACKAGES/$runtimeFullName"
__kvm_download "$runtimeFullName" "$runtimeFolder"
[[ $? == 1 ]] && return 1
$_KVM_COMMAND_NAME use "$versionOrAlias" "$persistent"
[[ -n $alias ]] && kvm alias "$alias" "$versionOrAlias"
fi
;;
"use" )
[ $# -gt 3 ] && $_KVM_COMMAND_NAME help && return
[ $# -lt 2 ] && $_KVM_COMMAND_NAME help && return
shift
local persistent=
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
local persistent="true"
elif [[ -n $1 ]]; then
local versionOrAlias=$1
fi
shift
done
if [[ $versionOrAlias == "none" ]]; then
echo "Removing $_KVM_RUNTIME_SHORT_NAME from process PATH"
# Strip other version from PATH
PATH=$(__kvm_strip_path "$PATH" "/bin")
if [[ -n $persistent && -e "$_KVM_ALIAS_DIR/default.alias" ]]; then
echo "Setting default $_KVM_RUNTIME_SHORT_NAME to none"
rm "$_KVM_ALIAS_DIR/default.alias"
fi
return 0
fi
local runtimeFullName=$(__kvm_requested_version_or_alias "$versionOrAlias")
local runtimeBin=$(__kvm_locate_runtime_bin_from_full_name "$runtimeFullName")
if [[ -z $runtimeBin ]]; then
echo "Cannot find $runtimeFullName, do you need to run '$_KVM_COMMAND_NAME install $versionOrAlias'?"
return 1
fi
echo "Adding" $runtimeBin "to process PATH"
PATH=$(__kvm_strip_path "$PATH" "/bin")
PATH=$(__kvm_prepend_path "$PATH" "$runtimeBin")
if [[ -n $persistent ]]; then
local runtimeVersion=$(__kvm_package_version "$runtimeFullName")
$_KVM_COMMAND_NAME alias default "$runtimeVersion"
fi
;;
"alias" )
[[ $# -gt 3 ]] && kvm help && return
[[ ! -e "$_KVM_ALIAS_DIR/" ]] && mkdir "$_KVM_ALIAS_DIR/" > /dev/null
if [[ $# == 1 ]]; then
echo ""
local format="%-20s %s\n"
printf "$format" "Alias" "Name"
printf "$format" "-----" "----"
if [ -d "$_KVM_ALIAS_DIR" ]; then
for __kvm_file in $(find "$_KVM_ALIAS_DIR" -name *.alias); do
local alias="$(basename $__kvm_file | sed 's/\.alias//')"
local name="$(cat $__kvm_file)"
printf "$format" "$alias" "$name"
done
fi
echo ""
return
fi
local name="$2"
if [[ $# == 2 ]]; then
[[ ! -e "$_KVM_ALIAS_DIR/$name.alias" ]] && echo "There is no alias called '$name'" && return
cat "$_KVM_ALIAS_DIR/$name.alias"
echo ""
return
fi
local runtimeFullName=$(__kvm_requested_version_or_alias "$3")
[[ ! -d "$_KVM_USER_PACKAGES/$runtimeFullName" ]] && echo "$runtimeFullName is not an installed $_KVM_RUNTIME_SHORT_NAME version" && return 1
local action="Setting"
[[ -e "$_KVM_ALIAS_DIR/$name.alias" ]] && action="Updating"
echo "$action alias '$name' to '$runtimeFullName'"
echo "$runtimeFullName" > "$_KVM_ALIAS_DIR/$name.alias"
;;
"unalias" )
[[ $# -ne 2 ]] && kvm help && return
local name=$2
local aliasPath="$_KVM_ALIAS_DIR/$name.alias"
[[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1
echo "Removing alias $name"
rm "$aliasPath" >> /dev/null 2>&1
;;
"list" )
[[ $# -gt 2 ]] && kvm help && return
[[ ! -d $_KVM_USER_PACKAGES ]] && echo "$_KVM_RUNTIME_FRIENDLY_NAME is not installed." && return 1
local searchGlob="$_KVM_RUNTIME_PACKAGE_NAME-*"
if [ $# == 2 ]; then
local versionOrAlias=$2
local searchGlob=$(__kvm_requested_version_or_alias "$versionOrAlias")
fi
echo ""
# Separate empty array declaration from initialization
# to avoid potential ZSH error: local:217: maximum nested function level reached
local arr
arr=()
# Z shell array-index starts at one.
local i=1
local format="%-20s %s\n"
if [ -d "$_KVM_ALIAS_DIR" ]; then
for __kvm_file in $(find "$_KVM_ALIAS_DIR" -name *.alias); do
arr[$i]="$(basename $__kvm_file | sed 's/\.alias//')/$(cat $__kvm_file)"
let i+=1
done
fi
local formatString="%-6s %-20s %-7s %-20s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Location" "Alias"
printf "$formatString" "------" "-------" "-------" "--------" "-----"
local formattedHome=`(echo $_KVM_USER_PACKAGES | sed s=$HOME=~=g)`
for f in $(find $_KVM_USER_PACKAGES -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;); do
local active=""
[[ $PATH == *"$_KVM_USER_PACKAGES/$f/bin"* ]] && local active=" *"
local pkgName=$(__kvm_package_runtime "$f")
local pkgVersion=$(__kvm_package_version "$f")
local alias=""
local delim=""
for i in "${arr[@]}"; do
temp="$_KVM_RUNTIME_PACKAGE_NAME-$pkgName.$pkgVersion"
temp2="$_KVM_RUNTIME_PACKAGE_NAME-$pkgName-x86.$pkgVersion"
if [[ ${i#*/} == $temp || ${i#*/} == $temp2 ]]; then
alias+="$delim${i%/*}"
delim=", "
fi
done
printf "$formatString" "$active" "$pkgVersion" "$pkgName" "$formattedHome" "$alias"
[[ $# == 2 ]] && echo "" && return 0
done
echo ""
[[ $# == 2 ]] && echo "$versionOrAlias not found" && return 1
;;
*)
echo "Unknown command $1"
return 1
esac
return 0
}
# Generate the command function using the constant defined above.
$_KVM_COMMAND_NAME list default >/dev/null && $_KVM_COMMAND_NAME use default >/dev/null || true