Updating build scripts to use dotnetsdk instead of kvm
This commit is contained in:
parent
f38d08a408
commit
361f083117
|
|
@ -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\kvm upgrade -runtime CLR -x86
|
||||
CALL packages\KoreBuild\build\kvm install default -runtime CoreCLR -x86
|
||||
CALL packages\KoreBuild\build\dotnetsdk upgrade -runtime CLR -x86
|
||||
CALL packages\KoreBuild\build\dotnetsdk install default -runtime CoreCLR -x86
|
||||
|
||||
:run
|
||||
CALL packages\KoreBuild\build\kvm use default -runtime CLR -x86
|
||||
CALL packages\KoreBuild\build\dotnetsdk use default -runtime CLR -x86
|
||||
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ if test ! -d packages/KoreBuild; then
|
|||
fi
|
||||
|
||||
if ! type k > /dev/null 2>&1; then
|
||||
source setup/kvm.sh
|
||||
source setup/dotnetsdk.sh
|
||||
fi
|
||||
|
||||
if ! type k > /dev/null 2>&1; then
|
||||
kvm upgrade
|
||||
dotnetsdk upgrade
|
||||
fi
|
||||
|
||||
mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"
|
||||
|
|
|
|||
9
build.sh
9
build.sh
|
|
@ -27,7 +27,12 @@ if test ! -d packages/KoreBuild; then
|
|||
mono .nuget/nuget.exe install Sake -version 0.2 -o packages -ExcludeVersion
|
||||
fi
|
||||
|
||||
. build/kvm.sh
|
||||
kvm upgrade
|
||||
if ! type k > /dev/null 2>&1; then
|
||||
source packages/KoreBuild/build/dotnetsdk.sh
|
||||
fi
|
||||
|
||||
if ! type k > /dev/null 2>&1; then
|
||||
dotnetsdk upgrade
|
||||
fi
|
||||
|
||||
mono packages/Sake/tools/Sake.exe -I packages/KoreBuild/build -f makefile.shade "$@"
|
||||
|
|
|
|||
|
|
@ -54,5 +54,5 @@ projectFile=''
|
|||
}
|
||||
}
|
||||
|
||||
macro name='K' command='string' workingdir='string' kvmUse='string'
|
||||
macro name='K' command='string' workingdir='string' dotnetsdkUse='string'
|
||||
k
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
@{/*
|
||||
|
||||
k
|
||||
Run klr commands in your project. Executes k sdk.
|
||||
Run dotnet commands in your project. Executes k cmd.
|
||||
|
||||
command=''
|
||||
kvmUse=''
|
||||
dotnetsdkUse=''
|
||||
|
||||
*/}
|
||||
|
||||
default kvmUse=''
|
||||
default dotnetsdkUse=''
|
||||
|
||||
var kvmPath='${Directory.GetCurrentDirectory()}\packages\KoreBuild\build\kvm'
|
||||
var dotnetsdkPath='${Directory.GetCurrentDirectory()}\packages\KoreBuild\build\dotnetsdk'
|
||||
|
||||
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='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='k' commandline='${command}' if='IsMono'
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
@Echo off
|
||||
|
||||
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0kvm.ps1' %*"
|
||||
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0dotnetsdk.ps1' %*"
|
||||
|
||||
IF EXIST "%USERPROFILE%\.kre\run-once.cmd" (
|
||||
CALL "%USERPROFILE%\.kre\run-once.cmd"
|
||||
DEL "%USERPROFILE%\.kre\run-once.cmd"
|
||||
IF EXIST "%USERPROFILE%\.dotnet\temp-set-envvars.cmd" (
|
||||
CALL "%USERPROFILE%\.dotnet\temp-set-envvars.cmd"
|
||||
DEL "%USERPROFILE%\.dotnet\temp-set-envvars.cmd"
|
||||
)
|
||||
|
|
@ -0,0 +1,855 @@
|
|||
param(
|
||||
[parameter(Position=0)]
|
||||
[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("w")][switch] $Wait = $false,
|
||||
[alias("a")]
|
||||
[string] $Alias = $null,
|
||||
[switch] $NoNative = $false,
|
||||
[parameter(Position=1, ValueFromRemainingArguments=$true)]
|
||||
[string[]]$Args=@(),
|
||||
[switch] $Quiet,
|
||||
[string] $OutputVariable,
|
||||
[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"
|
||||
|
||||
$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"
|
||||
|
||||
# Get or calculate globalDotNetPath
|
||||
$globalDotNetPath = $env:DOTNET_GLOBAL_PATH
|
||||
if(!$globalDotNetPath) { $globalDotNetPath = $env:ProgramFiles + "\$RuntimeProgramFilesName" }
|
||||
$globalDotNetRuntimesPath = $globalDotNetPath + "\runtimes"
|
||||
$feed = $env:DOTNET_FEED
|
||||
|
||||
# In some environments, like Azure Websites, the Write-* cmdlets don't work
|
||||
$useHostOutputMethods = $true
|
||||
|
||||
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 {
|
||||
@"
|
||||
.NET SDK Manager - Build 10206
|
||||
|
||||
USAGE: dotnetsdk <command> [options]
|
||||
|
||||
dotnetsdk upgrade [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-g|-Global] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
|
||||
install latest .NET Runtime from feed
|
||||
set 'default' alias to installed version
|
||||
add KRE 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
|
||||
-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
|
||||
|
||||
dotnetsdk list
|
||||
list .NET Runtime versions installed
|
||||
|
||||
dotnetsdk alias
|
||||
list .NET Runtime aliases which have been defined
|
||||
|
||||
dotnetsdk alias <alias>
|
||||
display value of the specified alias
|
||||
|
||||
dotnetsdk alias <alias> <semver>|<alias>|<package> [-X86][-Amd64] [-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
|
||||
|
||||
dotnetsdk unalias <alias>
|
||||
remove the specified alias
|
||||
|
||||
"@ -replace "`n","`r`n" | Console-Write
|
||||
}
|
||||
|
||||
function DotNetSdk-Global-Setup {
|
||||
$dotnetsdkBinPath = "$userDotNetPath\bin"
|
||||
|
||||
If (Needs-Elevation)
|
||||
{
|
||||
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -global -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 "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 $dotnetsdkBinPath\dotnetsdk.cmd"
|
||||
copy "$scriptFolder\dotnetsdk.cmd" "$dotnetsdkBinPath\dotnetsdk.cmd"
|
||||
|
||||
Console-Write "Adding $dotnetsdkBinPath to process PATH"
|
||||
Set-Path (Change-Path $env:Path $dotnetsdkBinPath ($dotnetsdkBinPath))
|
||||
|
||||
Console-Write "Adding $dotnetsdkBinPath to user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath $dotnetsdkBinPath ($dotnetsdkBinPath)
|
||||
[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 $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)
|
||||
}
|
||||
|
||||
function DotNetSdk-Upgrade {
|
||||
param(
|
||||
[boolean] $isGlobal
|
||||
)
|
||||
$Persistent = $true
|
||||
$Alias="default"
|
||||
DotNetSdk-Install "latest" $isGlobal
|
||||
}
|
||||
|
||||
function Add-Proxy-If-Specified {
|
||||
param(
|
||||
[System.Net.WebClient] $wc
|
||||
)
|
||||
if (!$Proxy) {
|
||||
$Proxy = $env:http_proxy
|
||||
}
|
||||
if ($Proxy) {
|
||||
$wp = New-Object System.Net.WebProxy($Proxy)
|
||||
$pb = New-Object UriBuilder($Proxy)
|
||||
if (!$pb.UserName) {
|
||||
$wp.Credentials = [System.Net.CredentialCache]::DefaultCredentials
|
||||
} else {
|
||||
$wp.Credentials = New-Object System.Net.NetworkCredential($pb.UserName, $pb.Password)
|
||||
}
|
||||
$wc.Proxy = $wp
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Find-Latest {
|
||||
param(
|
||||
[string] $platform,
|
||||
[string] $architecture
|
||||
)
|
||||
Console-Write "Determining latest version"
|
||||
|
||||
$url = "$feed/GetUpdates()?packageIds=%27$RuntimePackageName-$platform-win-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
Add-Proxy-If-Specified($wc)
|
||||
[xml]$xml = $wc.DownloadString($url)
|
||||
|
||||
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
|
||||
|
||||
if (String-IsEmptyOrWhitespace($version)) {
|
||||
throw "There are no runtimes for platform '$platform', architecture '$architecture' in the feed '$feed'"
|
||||
}
|
||||
|
||||
return $version
|
||||
}
|
||||
|
||||
function Do-DotNetSdk-Download {
|
||||
param(
|
||||
[string] $runtimeFullName,
|
||||
[string] $runtimesFolder
|
||||
)
|
||||
$parts = $runtimeFullName.Split(".", 2)
|
||||
|
||||
$url = "$feed/package/" + $parts[0] + "/" + $parts[1]
|
||||
$runtimeFolder = Join-Path $runtimesFolder $runtimeFullName
|
||||
$runtimeFile = Join-Path $runtimeFolder "$runtimeFullName.nupkg"
|
||||
|
||||
If (Test-Path $runtimeFolder) {
|
||||
if($Force)
|
||||
{
|
||||
rm $runtimeFolder -Recurse -Force
|
||||
} else {
|
||||
Console-Write "$runtimeFullName already installed."
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Console-Write "Downloading $runtimeFullName from $feed"
|
||||
|
||||
#Downloading to temp location
|
||||
$runtimeTempDownload = Join-Path $runtimesFolder "temp"
|
||||
$tempDownloadFile = Join-Path $runtimeTempDownload "$runtimeFullName.nupkg"
|
||||
|
||||
if(Test-Path $runtimeTempDownload) {
|
||||
del "$runtimeTempDownload\*" -recurse
|
||||
} else {
|
||||
md $runtimeTempDownload -Force | Out-Null
|
||||
}
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
Add-Proxy-If-Specified($wc)
|
||||
$wc.DownloadFile($url, $tempDownloadFile)
|
||||
|
||||
Do-DotNetSdk-Unpack $tempDownloadFile $runtimeTempDownload
|
||||
|
||||
md $runtimeFolder -Force | Out-Null
|
||||
Console-Write "Installing to $runtimeFolder"
|
||||
mv "$runtimeTempDownload\*" $runtimeFolder
|
||||
Remove-Item "$runtimeTempDownload" -Force | Out-Null
|
||||
}
|
||||
|
||||
function Do-DotNetSdk-Unpack {
|
||||
param(
|
||||
[string] $runtimeFile,
|
||||
[string] $runtimeFolder
|
||||
)
|
||||
Console-Write "Unpacking to $runtimeFolder"
|
||||
|
||||
$compressionLib = [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
|
||||
|
||||
if($compressionLib -eq $null) {
|
||||
try {
|
||||
# Shell will not recognize nupkg as a zip and throw, so rename it to zip
|
||||
$runtimeZip = [System.IO.Path]::ChangeExtension($runtimeFile, "zip")
|
||||
Rename-Item $runtimeFile $runtimeZip
|
||||
# Use the shell to uncompress the nupkg
|
||||
$shell_app=new-object -com shell.application
|
||||
$zip_file = $shell_app.namespace($runtimeZip)
|
||||
$destination = $shell_app.namespace($runtimeFolder)
|
||||
$destination.Copyhere($zip_file.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files
|
||||
}
|
||||
finally {
|
||||
# make it a nupkg again
|
||||
Rename-Item $runtimeZip $runtimeFile
|
||||
}
|
||||
} else {
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($runtimeFile, $runtimeFolder)
|
||||
}
|
||||
|
||||
If (Test-Path ($runtimeFolder + "\[Content_Types].xml")) {
|
||||
Remove-Item ($runtimeFolder + "\[Content_Types].xml")
|
||||
}
|
||||
If (Test-Path ($runtimeFolder + "\_rels\")) {
|
||||
Remove-Item ($runtimeFolder + "\_rels\") -Force -Recurse
|
||||
}
|
||||
If (Test-Path ($runtimeFolder + "\package\")) {
|
||||
Remove-Item ($runtimeFolder + "\package\") -Force -Recurse
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Install {
|
||||
param(
|
||||
[string] $versionOrAlias,
|
||||
[boolean] $isGlobal
|
||||
)
|
||||
if ($versionOrAlias -eq "latest") {
|
||||
$versionOrAlias = DotNetSdk-Find-Latest (Requested-Platform $defaultRuntime) (Requested-Architecture $defaultArch)
|
||||
}
|
||||
|
||||
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||
$runtimeFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
|
||||
} else {
|
||||
$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
|
||||
}
|
||||
|
||||
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||
Set-Variable -Name "selectedArch" -Value (Package-Arch $runtimeFullName) -Scope Script
|
||||
Set-Variable -Name "selectedRuntime" -Value (Package-Platform $runtimeFullName) -Scope Script
|
||||
|
||||
$runtimeFolder = "$packageFolder\$runtimeFullName"
|
||||
$folderExists = Test-Path $runtimeFolder
|
||||
|
||||
if ($folderExists -and $Force) {
|
||||
del $runtimeFolder -Recurse -Force
|
||||
$folderExists = $false;
|
||||
}
|
||||
|
||||
if ($folderExists) {
|
||||
Console-Write "Target folder '$runtimeFolder' already exists"
|
||||
} else {
|
||||
$tempUnpackFolder = Join-Path $packageFolder "temp"
|
||||
$tempDownloadFile = Join-Path $tempUnpackFolder "$runtimeFullName.nupkg"
|
||||
|
||||
if(Test-Path $tempUnpackFolder) {
|
||||
del "$tempUnpackFolder\*" -recurse
|
||||
} else {
|
||||
md $tempUnpackFolder -Force | Out-Null
|
||||
}
|
||||
copy $versionOrAlias $tempDownloadFile
|
||||
|
||||
Do-DotNetSdk-Unpack $tempDownloadFile $tempUnpackFolder
|
||||
md $runtimeFolder -Force | Out-Null
|
||||
Console-Write "Installing to $runtimeFolder"
|
||||
mv "$tempUnpackFolder\*" $runtimeFolder
|
||||
Remove-Item "$tempUnpackFolder" -Force | Out-Null
|
||||
}
|
||||
|
||||
$packageVersion = Package-Version $runtimeFullName
|
||||
|
||||
DotNetSdk-Use $packageVersion
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {
|
||||
DotNetSdk-Alias-Set $Alias $packageVersion
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Do-DotNetSdk-Download $runtimeFullName $packageFolder
|
||||
DotNetSdk-Use $versionOrAlias
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {
|
||||
DotNetSdk-Alias-Set "$Alias" $versionOrAlias
|
||||
}
|
||||
}
|
||||
|
||||
if ($runtimeFullName.Contains("CoreCLR")) {
|
||||
if ($NoNative) {
|
||||
Console-Write "Native image generation is skipped"
|
||||
}
|
||||
else {
|
||||
Console-Write "Compiling native images for $runtimeFullName to improve startup performance..."
|
||||
Start-Process $CrossGenCommand -Wait
|
||||
Console-Write "Finished native image compilation."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-List {
|
||||
$dotnetHome = $env:DOTNET_HOME
|
||||
if (!$dotnetHome) {
|
||||
$dotnetHome = "$globalDotNetPath;$userDotNetPath"
|
||||
}
|
||||
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
$aliases = Get-ChildItem ($userDotNetPath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }}
|
||||
|
||||
$items = @()
|
||||
foreach($portion in $dotnetHome.Split(';')) {
|
||||
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
|
||||
if (Test-Path("$path\runtimes")) {
|
||||
$items += Get-ChildItem ("$path\runtimes\dotnet-*") | List-Parts $aliases
|
||||
}
|
||||
}
|
||||
|
||||
$items | Sort-Object Version, Runtime, Architecture, Alias | Format-Table -AutoSize -Property @{name="Active";expression={$_.Active};alignment="center"}, "Version", "Runtime", "Architecture", "Location", "Alias"
|
||||
}
|
||||
|
||||
filter List-Parts {
|
||||
param($aliases)
|
||||
|
||||
$hasBin = Test-Path($_.FullName+"\bin")
|
||||
if (!$hasBin) {
|
||||
return
|
||||
}
|
||||
$active = $false
|
||||
foreach($portion in $env:Path.Split(';')) {
|
||||
# Append \ to the end because otherwise you might see
|
||||
# multiple active versions if the folders have the same
|
||||
# name prefix (like 1.0-beta and 1.0)
|
||||
if ($portion.StartsWith($_.FullName + "\")) {
|
||||
$active = $true
|
||||
}
|
||||
}
|
||||
|
||||
$fullAlias=""
|
||||
$delim=""
|
||||
|
||||
foreach($alias in $aliases){
|
||||
if($_.Name.Split('\', 2) -contains $alias.Name){
|
||||
$fullAlias += $delim + $alias.Alias
|
||||
$delim = ", "
|
||||
}
|
||||
}
|
||||
|
||||
$parts1 = $_.Name.Split('.', 2)
|
||||
$parts2 = $parts1[0].Split('-', 4)
|
||||
return New-Object PSObject -Property @{
|
||||
Active = if ($active) { "*" } else { "" }
|
||||
Version = $parts1[1]
|
||||
Runtime = $parts2[1]
|
||||
OperatingSystem = $parts2[2]
|
||||
Architecture = $parts2[3]
|
||||
Location = $_.Parent.FullName
|
||||
Alias = $fullAlias
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
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))
|
||||
|
||||
if ($Persistent) {
|
||||
Console-Write "Removing .NET Runtime from user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath "" ($globalDotNetRuntimesPath, $userDotNetRuntimesPath)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
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'?"
|
||||
}
|
||||
|
||||
Console-Write "Adding $runtimeBin to process PATH"
|
||||
Set-Path (Change-Path $env:Path $runtimeBin ($globalDotNetRuntimesPath, $userDotNetRuntimesPath))
|
||||
|
||||
if ($Persistent) {
|
||||
Console-Write "Adding $runtimeBin to user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath $runtimeBin ($globalDotNetRuntimesPath, $userDotNetRuntimesPath)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Alias-List {
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
|
||||
Get-ChildItem ($userDotNetPath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
|
||||
}
|
||||
|
||||
function DotNetSdk-Alias-Get {
|
||||
param(
|
||||
[string] $name
|
||||
)
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
$aliasFilePath=$userDotNetPath + "\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"))
|
||||
Console-Write "Alias '$name' is set to $aliasValue"
|
||||
}
|
||||
}
|
||||
|
||||
function DotNetSdk-Alias-Set {
|
||||
param(
|
||||
[string] $name,
|
||||
[string] $value
|
||||
)
|
||||
$runtimeFullName = Requested-VersionOrAlias $value
|
||||
$aliasFilePath = $userDotNetPath + "\alias\" + $name + ".txt"
|
||||
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
|
||||
Console-Write "$action alias '$name' to '$runtimeFullName'"
|
||||
md ($userDotNetPath + "\alias\") -Force | Out-Null
|
||||
$runtimeFullName | Out-File ($aliasFilePath) ascii
|
||||
}
|
||||
|
||||
function DotNetSdk-Unalias {
|
||||
param(
|
||||
[string] $name
|
||||
)
|
||||
$aliasPath=$userDotNetPath + "\alias\" + $name + ".txt"
|
||||
if (Test-Path -literalPath "$aliasPath") {
|
||||
Console-Write "Removing alias $name"
|
||||
Remove-Item -literalPath $aliasPath
|
||||
} else {
|
||||
Console-Write "Cannot remove alias, '$name' is not a valid alias name"
|
||||
$script:exitCode = 1 # Return non-zero exit code for scripting
|
||||
}
|
||||
}
|
||||
|
||||
function Locate-DotNetBinFromFullName() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
$dotnetHome = $env:DOTNET_HOME
|
||||
if (!$dotnetHome) {
|
||||
$dotnetHome = "$globalDotNetPath;$userDotNetPath"
|
||||
}
|
||||
foreach($portion in $dotnetHome.Split(';')) {
|
||||
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
|
||||
$runtimeBin = "$path\runtimes\$runtimeFullName\bin"
|
||||
if (Test-Path "$runtimeBin") {
|
||||
return $runtimeBin
|
||||
}
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Package-Version() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
return $runtimeFullName -replace '[^.]*.(.*)', '$1'
|
||||
}
|
||||
|
||||
function Package-Platform() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
return $runtimeFullName -replace 'dotnet-([^-]*).*', '$1'
|
||||
}
|
||||
|
||||
function Package-Arch() {
|
||||
param(
|
||||
[string] $runtimeFullName
|
||||
)
|
||||
return $runtimeFullName -replace 'dotnet-[^-]*-[^-]*-([^.]*).*', '$1'
|
||||
}
|
||||
|
||||
|
||||
function Requested-VersionOrAlias() {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
|
||||
|
||||
$runtimeBin = Locate-DotNetBinFromFullName $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
|
||||
$parts = $aliasValue.Split('.', 2)
|
||||
$pkgVersion = $parts[1]
|
||||
# dotnet-coreclr-win-x86
|
||||
$parts = $parts[0].Split('-', 4)
|
||||
$pkgPlatform = Requested-Platform $parts[1]
|
||||
$pkgArchitecture = Requested-Architecture $parts[3]
|
||||
} else {
|
||||
$pkgVersion = $versionOrAlias
|
||||
$pkgPlatform = Requested-Platform $defaultRuntime
|
||||
$pkgArchitecture = Requested-Architecture $defaultArch
|
||||
}
|
||||
return $RuntimePackageName + "-" + $pkgPlatform + "-win-" + $pkgArchitecture + "." + $pkgVersion
|
||||
}
|
||||
|
||||
function Requested-Platform() {
|
||||
param(
|
||||
[string] $default
|
||||
)
|
||||
if (!(String-IsEmptyOrWhitespace($selectedRuntime))) {return $selectedRuntime}
|
||||
return $default
|
||||
}
|
||||
|
||||
function Requested-Architecture() {
|
||||
param(
|
||||
[string] $default
|
||||
)
|
||||
if (!(String-IsEmptyOrWhitespace($selectedArch))) {return $selectedArch}
|
||||
return $default
|
||||
}
|
||||
|
||||
function Change-Path() {
|
||||
param(
|
||||
[string] $existingPaths,
|
||||
[string] $prependPath,
|
||||
[string[]] $removePaths
|
||||
)
|
||||
$newPath = $prependPath
|
||||
foreach($portion in $existingPaths.Split(';')) {
|
||||
$skip = $portion -eq ""
|
||||
foreach($removePath in $removePaths) {
|
||||
if ($portion.StartsWith($removePath)) {
|
||||
$skip = $true
|
||||
}
|
||||
}
|
||||
if (!$skip) {
|
||||
$newPath = $newPath + ";" + $portion
|
||||
}
|
||||
}
|
||||
return $newPath
|
||||
}
|
||||
|
||||
function Set-Path() {
|
||||
param(
|
||||
[string] $newPath
|
||||
)
|
||||
md $userDotNetPath -Force | Out-Null
|
||||
$env:Path = $newPath
|
||||
@"
|
||||
SET "PATH=$newPath"
|
||||
"@ | Out-File ($userDotNetPath + "\temp-set-envvars.cmd") ascii
|
||||
}
|
||||
|
||||
function Needs-Elevation() {
|
||||
if($AssumeElevated) {
|
||||
return $false
|
||||
}
|
||||
|
||||
$user = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$elevated = $user.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
||||
return -NOT $elevated
|
||||
}
|
||||
|
||||
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"}
|
||||
if ($Force) {$arguments = "$arguments -force"}
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {$arguments = "$arguments -alias '$Alias'"}
|
||||
return $arguments
|
||||
}
|
||||
|
||||
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"
|
||||
$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"
|
||||
$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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$script:capturedOut = @()
|
||||
function Console-Write() {
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$true)]
|
||||
[string] $message
|
||||
)
|
||||
if($OutputVariable) {
|
||||
# Update the capture output
|
||||
$script:capturedOut += @($message)
|
||||
}
|
||||
|
||||
if(!$Quiet) {
|
||||
if ($useHostOutputMethods) {
|
||||
try {
|
||||
Write-Host $message
|
||||
}
|
||||
catch {
|
||||
$script:useHostOutputMethods = $false
|
||||
Console-Write $message
|
||||
}
|
||||
}
|
||||
else {
|
||||
[Console]::WriteLine($message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Console-Write-Error() {
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$true)]
|
||||
[string] $message
|
||||
)
|
||||
if ($useHostOutputMethods) {
|
||||
try {
|
||||
Write-Error $message
|
||||
}
|
||||
catch {
|
||||
$script:useHostOutputMethods = $false
|
||||
Console-Write-Error $message
|
||||
}
|
||||
}
|
||||
else {
|
||||
[Console]::Error.WriteLine($message)
|
||||
}
|
||||
}
|
||||
|
||||
function Validate-Full-Package-Name-Arguments-Combination() {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
if ($versionOrAlias -like "dotnet-*" -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"};
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Console-Write-Error $_
|
||||
Console-Write "Type 'dotnetsdk help' for help on how to use dotnetsdk."
|
||||
$script:exitCode = -1
|
||||
}
|
||||
if ($Wait) {
|
||||
Console-Write "Press any key to continue ..."
|
||||
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
|
||||
}
|
||||
|
||||
# If the user specified an output variable, push the value up to the parent scope
|
||||
if($OutputVariable) {
|
||||
Set-Variable $OutputVariable $script:capturedOut -Scope 1
|
||||
}
|
||||
|
||||
exit $script:exitCode
|
||||
|
|
@ -0,0 +1,412 @@
|
|||
# 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
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{{ProjectGuid}}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>{Name}</RootNamespace>
|
||||
<AssemblyName>{Name}</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<BaseIntermediateOutputPath>obj/K</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\K</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;K10;{Defines}</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>{ExtraProperties}
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\K</OutputPath>
|
||||
<DefineConstants>TRACE;K10;{Defines}</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>{ExtraProperties}
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
{Files}
|
||||
<Content Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
{References}
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
{ProjectReferences}
|
||||
</ItemGroup>
|
||||
<Import Project="{CSharpTargetsPath}" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
768
build/kvm.ps1
768
build/kvm.ps1
|
|
@ -1,768 +0,0 @@
|
|||
param(
|
||||
[parameter(Position=0)]
|
||||
[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,
|
||||
[switch] $X86 = $false,
|
||||
[switch] $Amd64 = $false,
|
||||
#deprecated
|
||||
[switch] $X64 = $false,
|
||||
#deprecated
|
||||
[switch] $Svr50 = $false,
|
||||
#deprecated
|
||||
[switch] $Svrc50 = $false,
|
||||
[alias("w")][switch] $Wait = $false,
|
||||
[alias("a")]
|
||||
[string] $Alias = $null,
|
||||
[switch] $NoNative = $false,
|
||||
[parameter(Position=1, ValueFromRemainingArguments=$true)]
|
||||
[string[]]$Args=@()
|
||||
)
|
||||
|
||||
$selectedArch=$null;
|
||||
$defaultArch="x86"
|
||||
$selectedRuntime=$null
|
||||
$defaultRuntime="CLR"
|
||||
$userKrePath = $env:USERPROFILE + "\.kre"
|
||||
$userKrePackages = $userKrePath + "\packages"
|
||||
$globalKrePath = $env:ProgramFiles + "\KRE"
|
||||
$globalKrePackages = $globalKrePath + "\packages"
|
||||
$feed = $env:KRE_NUGET_API_URL
|
||||
|
||||
function String-IsEmptyOrWhitespace([string]$str) {
|
||||
return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0
|
||||
}
|
||||
|
||||
if (!$feed)
|
||||
{
|
||||
$feed = "https://www.myget.org/F/aspnetvnext/api/v2";
|
||||
}
|
||||
|
||||
$scriptPath = $myInvocation.MyCommand.Definition
|
||||
|
||||
function Kvm-Help {
|
||||
@"
|
||||
K Runtime Environment Version Manager - Build 10026
|
||||
|
||||
USAGE: kvm <command> [options]
|
||||
|
||||
kvm upgrade [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-g|-Global] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
|
||||
install latest KRE from feed
|
||||
set 'default' alias to installed version
|
||||
add KRE 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
|
||||
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
|
||||
|
||||
kvm install <semver>|<alias>|<nupkg>|latest [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-a|-Alias <alias>] [-g|-Global] [-f|-Force] [-NoNative]
|
||||
<semver>|<alias> install requested KRE from feed
|
||||
<nupkg> install requested KRE from package on local filesystem
|
||||
latest install latest KRE from feed
|
||||
add KRE bin to path of current command line
|
||||
-p|-Persistent add KRE bin to PATH environment variables persistently
|
||||
-a|-Alias <alias> set alias <alias> for requested KRE on install
|
||||
-g|-Global install to machine-wide location
|
||||
-f|-Force install even if specified version is already installed
|
||||
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
|
||||
|
||||
kvm use <semver>|<alias>|none [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-p|-Persistent] [-g|-Global]
|
||||
<semver>|<alias> add KRE bin to path of current command line
|
||||
none remove KRE bin from path of current command line
|
||||
-p|-Persistent add KRE bin to PATH environment variables persistently
|
||||
-g|-Global combined with -p to change machine PATH instead of user PATH
|
||||
|
||||
kvm list
|
||||
list KRE versions installed
|
||||
|
||||
kvm alias
|
||||
list KRE aliases which have been defined
|
||||
|
||||
kvm alias <alias>
|
||||
display value of the specified alias
|
||||
|
||||
kvm alias <alias> <semver>|<alias> [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR]
|
||||
<alias> The name of the alias to set
|
||||
<semver>|<alias> The KRE version to set the alias to. Alternatively use the version of the specified alias
|
||||
|
||||
kvm unalias <alias>
|
||||
remove the specified alias
|
||||
|
||||
"@ -replace "`n","`r`n" | Write-Host
|
||||
}
|
||||
|
||||
function Kvm-Global-Setup {
|
||||
$kvmBinPath = "$userKrePath\bin"
|
||||
|
||||
If (Needs-Elevation)
|
||||
{
|
||||
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -global -wait"
|
||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||
Write-Host "Adding $kvmBinPath to process PATH"
|
||||
Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath))
|
||||
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME"
|
||||
$envKreHome = $env:KRE_HOME
|
||||
$envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
|
||||
$envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath)
|
||||
$env:KRE_HOME = $envKreHome
|
||||
Write-Host "Setup complete"
|
||||
break
|
||||
}
|
||||
|
||||
$scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath)
|
||||
|
||||
Write-Host "Copying file $kvmBinPath\kvm.ps1"
|
||||
md $kvmBinPath -Force | Out-Null
|
||||
copy "$scriptFolder\kvm.ps1" "$kvmBinPath\kvm.ps1"
|
||||
|
||||
Write-Host "Copying file $kvmBinPath\kvm.cmd"
|
||||
copy "$scriptFolder\kvm.cmd" "$kvmBinPath\kvm.cmd"
|
||||
|
||||
Write-Host "Adding $kvmBinPath to process PATH"
|
||||
Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath))
|
||||
|
||||
Write-Host "Adding $kvmBinPath to user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath $kvmBinPath ($kvmBinPath)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
|
||||
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME"
|
||||
$envKreHome = $env:KRE_HOME
|
||||
$envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
|
||||
$envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath)
|
||||
$env:KRE_HOME = $envKreHome
|
||||
|
||||
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to machine KRE_HOME"
|
||||
$machineKreHome = [Environment]::GetEnvironmentVariable("KRE_HOME", [System.EnvironmentVariableTarget]::Machine)
|
||||
$machineKreHome = Change-Path $machineKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
|
||||
$machineKreHome = Change-Path $machineKreHome $globalKrePath ($globalKrePath)
|
||||
[Environment]::SetEnvironmentVariable("KRE_HOME", $machineKreHome, [System.EnvironmentVariableTarget]::Machine)
|
||||
}
|
||||
|
||||
function Kvm-Global-Upgrade {
|
||||
$Persistent = $true
|
||||
$Alias="default"
|
||||
$versionOrAlias = Kvm-Find-Latest $selectedRuntime $selectedArch
|
||||
If (Needs-Elevation) {
|
||||
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' install '$versionOrAlias' -global $(Requested-Switches) -wait"
|
||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||
Kvm-Set-Global-Process-Path $versionOrAlias
|
||||
break
|
||||
}
|
||||
Kvm-Install $versionOrAlias $true
|
||||
}
|
||||
|
||||
function Kvm-Upgrade {
|
||||
$Persistent = $true
|
||||
$Alias="default"
|
||||
Kvm-Install "latest" $false
|
||||
}
|
||||
|
||||
function Add-Proxy-If-Specified {
|
||||
param(
|
||||
[System.Net.WebClient] $wc
|
||||
)
|
||||
if (!$Proxy) {
|
||||
$Proxy = $env:http_proxy
|
||||
}
|
||||
if ($Proxy) {
|
||||
$wp = New-Object System.Net.WebProxy($Proxy)
|
||||
$pb = New-Object UriBuilder($Proxy)
|
||||
if (!$pb.UserName) {
|
||||
$wp.Credentials = [System.Net.CredentialCache]::DefaultCredentials
|
||||
} else {
|
||||
$wp.Credentials = New-Object System.Net.NetworkCredential($pb.UserName, $pb.Password)
|
||||
}
|
||||
$wc.Proxy = $wp
|
||||
}
|
||||
}
|
||||
|
||||
function Kvm-Find-Latest {
|
||||
param(
|
||||
[string] $platform,
|
||||
[string] $architecture
|
||||
)
|
||||
Write-Host "Determining latest version"
|
||||
|
||||
$url = "$feed/GetUpdates()?packageIds=%27KRE-$platform-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
|
||||
Add-Proxy-If-Specified($wc)
|
||||
[xml]$xml = $wc.DownloadString($url)
|
||||
|
||||
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
|
||||
|
||||
if (String-IsEmptyOrWhitespace($version)) {
|
||||
throw "There are no packages for platform '$platform', architecture '$architecture' in the feed '$feed'"
|
||||
}
|
||||
|
||||
return $version
|
||||
}
|
||||
|
||||
function Do-Kvm-Download {
|
||||
param(
|
||||
[string] $kreFullName,
|
||||
[string] $packagesFolder
|
||||
)
|
||||
$parts = $kreFullName.Split(".", 2)
|
||||
|
||||
$url = "$feed/package/" + $parts[0] + "/" + $parts[1]
|
||||
$kreFolder = Join-Path $packagesFolder $kreFullName
|
||||
$kreFile = Join-Path $kreFolder "$kreFullName.nupkg"
|
||||
|
||||
If (Test-Path $kreFolder) {
|
||||
if($Force)
|
||||
{
|
||||
rm $kreFolder -Recurse -Force
|
||||
} else {
|
||||
Write-Host "$kreFullName already installed."
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Downloading" $kreFullName "from $feed"
|
||||
|
||||
#Downloading to temp location
|
||||
$kreTempDownload = Join-Path $packagesFolder "temp"
|
||||
$tempKreFile = Join-Path $kreTempDownload "$kreFullName.nupkg"
|
||||
|
||||
if(Test-Path $kreTempDownload) {
|
||||
del "$kreTempDownload\*" -recurse
|
||||
} else {
|
||||
md $kreTempDownload -Force | Out-Null
|
||||
}
|
||||
|
||||
$wc = New-Object System.Net.WebClient
|
||||
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
|
||||
Add-Proxy-If-Specified($wc)
|
||||
$wc.DownloadFile($url, $tempKreFile)
|
||||
|
||||
Do-Kvm-Unpack $tempKreFile $kreTempDownload
|
||||
|
||||
md $kreFolder -Force | Out-Null
|
||||
Write-Host "Installing to $kreFolder"
|
||||
mv "$kreTempDownload\*" $kreFolder
|
||||
Remove-Item "$kreTempDownload" -Force | Out-Null
|
||||
}
|
||||
|
||||
function Do-Kvm-Unpack {
|
||||
param(
|
||||
[string] $kreFile,
|
||||
[string] $kreFolder
|
||||
)
|
||||
Write-Host "Unpacking to" $kreFolder
|
||||
|
||||
$compressionLib = [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
|
||||
|
||||
if($compressionLib -eq $null) {
|
||||
try {
|
||||
# Shell will not recognize nupkg as a zip and throw, so rename it to zip
|
||||
$kreZip = [System.IO.Path]::ChangeExtension($kreFile, "zip")
|
||||
Rename-Item $kreFile $kreZip
|
||||
# Use the shell to uncompress the nupkg
|
||||
$shell_app=new-object -com shell.application
|
||||
$zip_file = $shell_app.namespace($kreZip)
|
||||
$destination = $shell_app.namespace($kreFolder)
|
||||
$destination.Copyhere($zip_file.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files
|
||||
}
|
||||
finally {
|
||||
# make it a nupkg again
|
||||
Rename-Item $kreZip $kreFile
|
||||
}
|
||||
} else {
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($kreFile, $kreFolder)
|
||||
}
|
||||
|
||||
If (Test-Path ($kreFolder + "\[Content_Types].xml")) {
|
||||
Remove-Item ($kreFolder + "\[Content_Types].xml")
|
||||
}
|
||||
If (Test-Path ($kreFolder + "\_rels\")) {
|
||||
Remove-Item ($kreFolder + "\_rels\") -Force -Recurse
|
||||
}
|
||||
If (Test-Path ($kreFolder + "\package\")) {
|
||||
Remove-Item ($kreFolder + "\package\") -Force -Recurse
|
||||
}
|
||||
}
|
||||
|
||||
function Kvm-Install {
|
||||
param(
|
||||
[string] $versionOrAlias,
|
||||
[boolean] $isGlobal
|
||||
)
|
||||
if ($versionOrAlias -eq "latest") {
|
||||
$versionOrAlias = Kvm-Find-Latest (Requested-Platform $defaultRuntime) (Requested-Architecture $defaultArch)
|
||||
}
|
||||
|
||||
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||
$kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
|
||||
} else {
|
||||
$kreFullName = 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
|
||||
Kvm-Set-Global-Process-Path $versionOrAlias
|
||||
break
|
||||
}
|
||||
$packageFolder = $globalKrePackages
|
||||
} else {
|
||||
$packageFolder = $userKrePackages
|
||||
}
|
||||
|
||||
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||
Set-Variable -Name "selectedArch" -Value (Package-Arch $kreFullName) -Scope Script
|
||||
Set-Variable -Name "selectedRuntime" -Value (Package-Platform $kreFullName) -Scope Script
|
||||
|
||||
$kreFolder = "$packageFolder\$kreFullName"
|
||||
$folderExists = Test-Path $kreFolder
|
||||
|
||||
if ($folderExists -and $Force) {
|
||||
del $kreFolder -Recurse -Force
|
||||
$folderExists = $false;
|
||||
}
|
||||
|
||||
if ($folderExists) {
|
||||
Write-Host "Target folder '$kreFolder' already exists"
|
||||
} else {
|
||||
$tempUnpackFolder = Join-Path $packageFolder "temp"
|
||||
$tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg"
|
||||
|
||||
if(Test-Path $tempUnpackFolder) {
|
||||
del "$tempUnpackFolder\*" -recurse
|
||||
} else {
|
||||
md $tempUnpackFolder -Force | Out-Null
|
||||
}
|
||||
copy $versionOrAlias $tempKreFile
|
||||
|
||||
Do-Kvm-Unpack $tempKreFile $tempUnpackFolder
|
||||
md $kreFolder -Force | Out-Null
|
||||
Write-Host "Installing to $kreFolder"
|
||||
mv "$tempUnpackFolder\*" $kreFolder
|
||||
Remove-Item "$tempUnpackFolder" -Force | Out-Null
|
||||
}
|
||||
|
||||
$packageVersion = Package-Version $kreFullName
|
||||
|
||||
Kvm-Use $packageVersion
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {
|
||||
Kvm-Alias-Set $Alias $packageVersion
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Do-Kvm-Download $kreFullName $packageFolder
|
||||
Kvm-Use $versionOrAlias
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {
|
||||
Kvm-Alias-Set "$Alias" $versionOrAlias
|
||||
}
|
||||
}
|
||||
|
||||
if ($kreFullName.Contains("CoreCLR")) {
|
||||
if ($NoNative) {
|
||||
Write-Host "Native image generation is skipped"
|
||||
}
|
||||
else {
|
||||
Write-Host "Compiling native images for $kreFullName to improve startup performance..."
|
||||
Start-Process "K" -ArgumentList "crossgen" -Wait
|
||||
Write-Host "Finished native image compilation."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Kvm-List {
|
||||
$kreHome = $env:KRE_HOME
|
||||
if (!$kreHome) {
|
||||
$kreHome = "$globalKrePath;$userKrePath"
|
||||
}
|
||||
|
||||
md ($userKrePath + "\alias\") -Force | Out-Null
|
||||
$aliases = Get-ChildItem ($userKrePath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }}
|
||||
|
||||
$items = @()
|
||||
foreach($portion in $kreHome.Split(';')) {
|
||||
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
|
||||
if (Test-Path("$path\packages")) {
|
||||
$items += Get-ChildItem ("$path\packages\KRE-*") | List-Parts $aliases
|
||||
}
|
||||
}
|
||||
|
||||
$items | Sort-Object Version, Runtime, Architecture, Alias | Format-Table -AutoSize -Property @{name="Active";expression={$_.Active};alignment="center"}, "Version", "Runtime", "Architecture", "Location", "Alias"
|
||||
}
|
||||
|
||||
filter List-Parts {
|
||||
param($aliases)
|
||||
|
||||
$hasBin = Test-Path($_.FullName+"\bin")
|
||||
if (!$hasBin) {
|
||||
return
|
||||
}
|
||||
$active = $false
|
||||
foreach($portion in $env:Path.Split(';')) {
|
||||
if ($portion.StartsWith($_.FullName)) {
|
||||
$active = $true
|
||||
}
|
||||
}
|
||||
|
||||
$fullAlias=""
|
||||
$delim=""
|
||||
|
||||
foreach($alias in $aliases){
|
||||
if($_.Name.Split('\', 2) -contains $alias.Name){
|
||||
$fullAlias += $delim + $alias.Alias
|
||||
$delim = ", "
|
||||
}
|
||||
}
|
||||
|
||||
$parts1 = $_.Name.Split('.', 2)
|
||||
$parts2 = $parts1[0].Split('-', 3)
|
||||
return New-Object PSObject -Property @{
|
||||
Active = if ($active) { "*" } else { "" }
|
||||
Version = $parts1[1]
|
||||
Runtime = $parts2[1]
|
||||
Architecture = $parts2[2]
|
||||
Location = $_.Parent.FullName
|
||||
Alias = $fullAlias
|
||||
}
|
||||
}
|
||||
|
||||
function Kvm-Global-Use {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
If (Needs-Elevation) {
|
||||
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' use '$versionOrAlias' -global $(Requested-Switches) -wait"
|
||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||
Kvm-Set-Global-Process-Path $versionOrAlias
|
||||
break
|
||||
}
|
||||
|
||||
Kvm-Set-Global-Process-Path "$versionOrAlias"
|
||||
|
||||
if ($versionOrAlias -eq "none") {
|
||||
if ($Persistent) {
|
||||
Write-Host "Removing KRE from machine PATH"
|
||||
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
|
||||
$machinePath = Change-Path $machinePath "" ($globalKrePackages, $userKrePackages)
|
||||
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$kreFullName = Requested-VersionOrAlias "$versionOrAlias"
|
||||
$kreBin = Locate-KreBinFromFullName $kreFullName
|
||||
if ($kreBin -eq $null) {
|
||||
throw "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
||||
}
|
||||
|
||||
if ($Persistent) {
|
||||
Write-Host "Adding $kreBin to machine PATH"
|
||||
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
|
||||
$machinePath = Change-Path $machinePath $kreBin ($globalKrePackages, $userKrePackages)
|
||||
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
|
||||
}
|
||||
}
|
||||
|
||||
function Kvm-Set-Global-Process-Path {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
if ($versionOrAlias -eq "none") {
|
||||
Write-Host "Removing KRE from process PATH"
|
||||
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
|
||||
return
|
||||
}
|
||||
|
||||
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
||||
$kreBin = Locate-KreBinFromFullName $kreFullName
|
||||
if ($kreBin -eq $null) {
|
||||
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "Adding" $kreBin "to process PATH"
|
||||
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
|
||||
}
|
||||
|
||||
function Kvm-Use {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
if ($versionOrAlias -eq "none") {
|
||||
Write-Host "Removing KRE from process PATH"
|
||||
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
|
||||
|
||||
if ($Persistent) {
|
||||
Write-Host "Removing KRE from user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath "" ($globalKrePackages, $userKrePackages)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
||||
|
||||
$kreBin = Locate-KreBinFromFullName $kreFullName
|
||||
if ($kreBin -eq $null) {
|
||||
throw "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
||||
}
|
||||
|
||||
Write-Host "Adding" $kreBin "to process PATH"
|
||||
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
|
||||
|
||||
if ($Persistent) {
|
||||
Write-Host "Adding $kreBin to user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath $kreBin ($globalKrePackages, $userKrePackages)
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
}
|
||||
|
||||
function Kvm-Alias-List {
|
||||
md ($userKrePath + "\alias\") -Force | Out-Null
|
||||
|
||||
Get-ChildItem ($userKrePath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
|
||||
}
|
||||
|
||||
function Kvm-Alias-Get {
|
||||
param(
|
||||
[string] $name
|
||||
)
|
||||
md ($userKrePath + "\alias\") -Force | Out-Null
|
||||
$aliasFilePath=$userKrePath + "\alias\" + $name + ".txt"
|
||||
if (!(Test-Path $aliasFilePath)) {
|
||||
Write-Host "Alias '$name' does not exist"
|
||||
} else {
|
||||
Write-Host "Alias '$name' is set to" (Get-Content ($userKrePath + "\alias\" + $name + ".txt"))
|
||||
}
|
||||
}
|
||||
|
||||
function Kvm-Alias-Set {
|
||||
param(
|
||||
[string] $name,
|
||||
[string] $value
|
||||
)
|
||||
$kreFullName = Requested-VersionOrAlias $value
|
||||
$aliasFilePath = $userKrePath + "\alias\" + $name + ".txt"
|
||||
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
|
||||
Write-Host "$action alias '$name' to '$kreFullName'"
|
||||
md ($userKrePath + "\alias\") -Force | Out-Null
|
||||
$kreFullName | Out-File ($aliasFilePath) ascii
|
||||
}
|
||||
|
||||
function Kvm-Unalias {
|
||||
param(
|
||||
[string] $name
|
||||
)
|
||||
$aliasPath=$userKrePath + "\alias\" + $name + ".txt"
|
||||
if (Test-Path -literalPath "$aliasPath") {
|
||||
Write-Host "Removing alias $name"
|
||||
Remove-Item -literalPath $aliasPath
|
||||
} else {
|
||||
Write-Host "Cannot remove alias, '$name' is not a valid alias name"
|
||||
}
|
||||
}
|
||||
|
||||
function Locate-KreBinFromFullName() {
|
||||
param(
|
||||
[string] $kreFullName
|
||||
)
|
||||
$kreHome = $env:KRE_HOME
|
||||
if (!$kreHome) {
|
||||
$kreHome = "$globalKrePath;$userKrePath"
|
||||
}
|
||||
foreach($portion in $kreHome.Split(';')) {
|
||||
$path = [System.Environment]::ExpandEnvironmentVariables($portion)
|
||||
$kreBin = "$path\packages\$kreFullName\bin"
|
||||
if (Test-Path "$kreBin") {
|
||||
return $kreBin
|
||||
}
|
||||
}
|
||||
return $null
|
||||
}
|
||||
|
||||
function Package-Version() {
|
||||
param(
|
||||
[string] $kreFullName
|
||||
)
|
||||
return $kreFullName -replace '[^.]*.(.*)', '$1'
|
||||
}
|
||||
|
||||
function Package-Platform() {
|
||||
param(
|
||||
[string] $kreFullName
|
||||
)
|
||||
return $kreFullName -replace 'KRE-([^-]*).*', '$1'
|
||||
}
|
||||
|
||||
function Package-Arch() {
|
||||
param(
|
||||
[string] $kreFullName
|
||||
)
|
||||
return $kreFullName -replace 'KRE-[^-]*-([^.]*).*', '$1'
|
||||
}
|
||||
|
||||
|
||||
function Requested-VersionOrAlias() {
|
||||
param(
|
||||
[string] $versionOrAlias
|
||||
)
|
||||
If (Test-Path ($userKrePath + "\alias\" + $versionOrAlias + ".txt")) {
|
||||
$aliasValue = Get-Content ($userKrePath + "\alias\" + $versionOrAlias + ".txt")
|
||||
$parts = $aliasValue.Split('.', 2)
|
||||
$pkgVersion = $parts[1]
|
||||
$parts =$parts[0].Split('-', 3)
|
||||
$pkgPlatform = Requested-Platform $parts[1]
|
||||
$pkgArchitecture = Requested-Architecture $parts[2]
|
||||
} else {
|
||||
$pkgVersion = $versionOrAlias
|
||||
$pkgPlatform = Requested-Platform $defaultRuntime
|
||||
$pkgArchitecture = Requested-Architecture $defaultArch
|
||||
}
|
||||
return "KRE-" + $pkgPlatform + "-" + $pkgArchitecture + "." + $pkgVersion
|
||||
}
|
||||
|
||||
function Requested-Platform() {
|
||||
param(
|
||||
[string] $default
|
||||
)
|
||||
if (!(String-IsEmptyOrWhitespace($selectedRuntime))) {return $selectedRuntime}
|
||||
return $default
|
||||
}
|
||||
|
||||
function Requested-Architecture() {
|
||||
param(
|
||||
[string] $default
|
||||
)
|
||||
if (!(String-IsEmptyOrWhitespace($selectedArch))) {return $selectedArch}
|
||||
return $default
|
||||
}
|
||||
|
||||
function Change-Path() {
|
||||
param(
|
||||
[string] $existingPaths,
|
||||
[string] $prependPath,
|
||||
[string[]] $removePaths
|
||||
)
|
||||
$newPath = $prependPath
|
||||
foreach($portion in $existingPaths.Split(';')) {
|
||||
$skip = $portion -eq ""
|
||||
foreach($removePath in $removePaths) {
|
||||
if ($portion.StartsWith($removePath)) {
|
||||
$skip = $true
|
||||
}
|
||||
}
|
||||
if (!$skip) {
|
||||
$newPath = $newPath + ";" + $portion
|
||||
}
|
||||
}
|
||||
return $newPath
|
||||
}
|
||||
|
||||
function Set-Path() {
|
||||
param(
|
||||
[string] $newPath
|
||||
)
|
||||
md $userKrePath -Force | Out-Null
|
||||
$env:Path = $newPath
|
||||
@"
|
||||
SET "PATH=$newPath"
|
||||
"@ | Out-File ($userKrePath + "\run-once.cmd") ascii
|
||||
}
|
||||
|
||||
function Needs-Elevation() {
|
||||
$user = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$elevated = $user.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
||||
return -NOT $elevated
|
||||
}
|
||||
|
||||
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"}
|
||||
if ($Force) {$arguments = "$arguments -force"}
|
||||
if (!$(String-IsEmptyOrWhitespace($Alias))) {$arguments = "$arguments -alias '$Alias'"}
|
||||
return $arguments
|
||||
}
|
||||
|
||||
function Validate-And-Santitise-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"
|
||||
$match = $validRuntimes | ? { $_ -like $Runtime } | Select -First 1
|
||||
if (!$match) {throw "'$runtime' is not a valid runtime"}
|
||||
Set-Variable -Name "selectedRuntime" -Value $match -Scope Script
|
||||
} elseif ($Svr50) {
|
||||
Write-Host "Warning: -svr50 is deprecated, use -runtime CLR for new packages."
|
||||
Set-Variable -Name "selectedRuntime" -Value "svr50" -Scope Script
|
||||
} elseif ($Svrc50) {
|
||||
Write-Host "Warning: -svrc50 is deprecated, use -runtime CoreCLR for new packages."
|
||||
Set-Variable -Name "selectedRuntime" -Value "svrc50" -Scope Script
|
||||
}
|
||||
|
||||
if ($X64) {
|
||||
Write-Host "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
|
||||
}
|
||||
}
|
||||
|
||||
$exitCode = 0
|
||||
try {
|
||||
Validate-And-Santitise-Switches
|
||||
if ($Global) {
|
||||
switch -wildcard ($Command + " " + $Args.Count) {
|
||||
"setup 0" {Kvm-Global-Setup}
|
||||
"upgrade 0" {Kvm-Global-Upgrade}
|
||||
"install 1" {Kvm-Install $Args[0] $true}
|
||||
"use 1" {Kvm-Global-Use $Args[0]}
|
||||
default {throw "Unknown command, or global switch not supported"};
|
||||
}
|
||||
} else {
|
||||
switch -wildcard ($Command + " " + $Args.Count) {
|
||||
"setup 0" {Kvm-Global-Setup}
|
||||
"upgrade 0" {Kvm-Upgrade}
|
||||
"install 1" {Kvm-Install $Args[0] $false}
|
||||
"list 0" {Kvm-List}
|
||||
"use 1" {Kvm-Use $Args[0]}
|
||||
"alias 0" {Kvm-Alias-List}
|
||||
"alias 1" {Kvm-Alias-Get $Args[0]}
|
||||
"alias 2" {Kvm-Alias-Set $Args[0] $Args[1]}
|
||||
"unalias 1" {Kvm-Unalias $Args[0]}
|
||||
"help 0" {Kvm-Help}
|
||||
" 0" {Kvm-Help}
|
||||
default {throw "Unknown command"};
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error $_
|
||||
Write-Host "Type 'kvm help' for help on how to use kvm."
|
||||
$exitCode = -1
|
||||
}
|
||||
if ($Wait) {
|
||||
Write-Host "Press any key to continue ..."
|
||||
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
|
||||
}
|
||||
|
||||
exit $exitCode
|
||||
405
build/kvm.sh
405
build/kvm.sh
|
|
@ -1,405 +0,0 @@
|
|||
# kvm.sh
|
||||
# Source this file from your .bash-profile or script to use
|
||||
_kvm_has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
if _kvm_has "unsetopt"; then
|
||||
unsetopt nomatch 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -z "$KRE_USER_HOME" ]; then
|
||||
eval KRE_USER_HOME=~/.kre
|
||||
fi
|
||||
|
||||
KRE_USER_PACKAGES="$KRE_USER_HOME/packages"
|
||||
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 Needs curl to proceed.' >&2;
|
||||
return 1
|
||||
fi
|
||||
|
||||
local url="$KRE_FEED/GetUpdates()?packageIds=%27KRE-$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#$KRE_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$KRE_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$KRE_USER_PACKAGES/[^/]*$2[^:]*##g"
|
||||
}
|
||||
|
||||
_kvm_prepend_path() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "$2"
|
||||
else
|
||||
echo "$2:$1"
|
||||
fi
|
||||
}
|
||||
|
||||
_kvm_package_version() {
|
||||
local kreFullName="$1"
|
||||
echo "$kreFullName" | sed "s/[^.]*.\(.*\)/\1/"
|
||||
}
|
||||
|
||||
_kvm_package_name() {
|
||||
local kreFullName="$1"
|
||||
echo "$kreFullName" | sed "s/\([^.]*\).*/\1/"
|
||||
}
|
||||
|
||||
_kvm_package_runtime() {
|
||||
local kreFullName="$1"
|
||||
echo "$kreFullName" | sed "s/KRE-\([^.-]*\).*/\1/"
|
||||
}
|
||||
|
||||
_kvm_download() {
|
||||
local kreFullName="$1"
|
||||
local kreFolder="$2"
|
||||
|
||||
local pkgName=$(_kvm_package_name "$kreFullName")
|
||||
local pkgVersion=$(_kvm_package_version "$kreFullName")
|
||||
local url="$KRE_FEED/package/$pkgName/$pkgVersion"
|
||||
local kreFile="$kreFolder/$kreFullName.nupkg"
|
||||
|
||||
if [ -e "$kreFolder" ]; then
|
||||
echo "$kreFullName already installed."
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Downloading $kreFullName from $KRE_FEED"
|
||||
|
||||
if ! _kvm_has "curl"; then
|
||||
echo "KVM Needs curl to proceed." >&2;
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$kreFolder" > /dev/null 2>&1
|
||||
|
||||
local httpResult=$(curl -L -D - -u aspnetreadonly:4d8a2d9c-7b80-4162-9978-47e918c9658c "$url" -o "$kreFile" 2>/dev/null | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
|
||||
|
||||
[[ $httpResult == "404" ]] && echo "$kreFullName was not found in repository $KRE_FEED" && return 1
|
||||
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $kreFullName from $KRE_FEED" && return 1
|
||||
|
||||
_kvm_unpack $kreFile $kreFolder
|
||||
return $?
|
||||
}
|
||||
|
||||
_kvm_unpack() {
|
||||
local kreFile="$1"
|
||||
local kreFolder="$2"
|
||||
|
||||
echo "Installing to $kreFolder"
|
||||
|
||||
if ! _kvm_has "unzip"; then
|
||||
echo "KVM Needs unzip to proceed." >&2;
|
||||
return 1
|
||||
fi
|
||||
|
||||
unzip $kreFile -d $kreFolder > /dev/null 2>&1
|
||||
|
||||
[ -e "$kreFolder/[Content_Types].xml" ] && rm "$kreFolder/[Content_Types].xml"
|
||||
|
||||
[ -e "$kreFolder/_rels/" ] && rm -rf "$kreFolder/_rels/"
|
||||
|
||||
[ -e "$kreFolder/package/" ] && rm -rf "$kreFolder/_package/"
|
||||
|
||||
#Set shell commands as executable
|
||||
find "$kreFolder/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"
|
||||
|
||||
if [ -e "$KRE_USER_HOME/alias/$versionOrAlias.alias" ]; then
|
||||
local kreFullName=$(cat "$KRE_USER_HOME/alias/$versionOrAlias.alias")
|
||||
local pkgName=$(echo $kreFullName | sed "s/\([^.]*\).*/\1/")
|
||||
local pkgVersion=$(echo $kreFullName | sed "s/[^.]*.\(.*\)/\1/")
|
||||
local pkgPlatform=$(echo "$pkgName" | sed "s/KRE-\([^.-]*\).*/\1/")
|
||||
else
|
||||
local pkgVersion=$versionOrAlias
|
||||
local pkgPlatform="Mono"
|
||||
fi
|
||||
|
||||
echo "KRE-$pkgPlatform.$pkgVersion"
|
||||
}
|
||||
|
||||
# This will be more relevant if we support global installs
|
||||
_kvm_locate_kre_bin_from_full_name() {
|
||||
local kreFullName=$1
|
||||
[ -e "$KRE_USER_PACKAGES/$kreFullName/bin" ] && echo "$KRE_USER_PACKAGES/$kreFullName/bin" && return
|
||||
}
|
||||
|
||||
kvm()
|
||||
{
|
||||
if [ $# -lt 1 ]; then
|
||||
kvm help
|
||||
return
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"help" )
|
||||
echo ""
|
||||
echo "K Runtime Environment Version Manager - Build 10026"
|
||||
echo ""
|
||||
echo "USAGE: kvm <command> [options]"
|
||||
echo ""
|
||||
echo "kvm upgrade"
|
||||
echo "install latest KRE from feed"
|
||||
echo "add KRE bin to path of current command line"
|
||||
echo "set installed version as default"
|
||||
echo ""
|
||||
echo "kvm install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p -persistent]"
|
||||
echo "<semver>|<alias> install requested KRE from feed"
|
||||
echo "<nupkg> install requested KRE from local package on filesystem"
|
||||
echo "latest install latest version of KRE from feed"
|
||||
echo "-a|-alias <alias> set alias <alias> for requested KRE on install"
|
||||
echo "-p -persistent set installed version as default"
|
||||
echo "add KRE bin to path of current command line"
|
||||
echo ""
|
||||
echo "kvm use <semver>|<alias>|none [-p -persistent]"
|
||||
echo "<semver>|<alias> add KRE bin to path of current command line "
|
||||
echo "none remove KRE bin from path of current command line"
|
||||
echo "-p -persistent set selected version as default"
|
||||
echo ""
|
||||
echo "kvm list"
|
||||
echo "list KRE versions installed "
|
||||
echo ""
|
||||
echo "kvm alias"
|
||||
echo "list KRE aliases which have been defined"
|
||||
echo ""
|
||||
echo "kvm alias <alias>"
|
||||
echo "display value of the specified alias"
|
||||
echo ""
|
||||
echo "kvm alias <alias> <semver>"
|
||||
echo "<alias> The name of the alias to set"
|
||||
echo "<semver>|<alias> The KRE version to set the alias to. Alternatively use the version of the specified alias"
|
||||
echo ""
|
||||
echo "kvm unalias <alias>"
|
||||
echo "remove the specified alias"
|
||||
echo ""
|
||||
;;
|
||||
|
||||
"upgrade" )
|
||||
[ $# -ne 1 ] && kvm help && return
|
||||
kvm install latest -p
|
||||
;;
|
||||
|
||||
"install" )
|
||||
[ $# -lt 2 ] && kvm help && return
|
||||
shift
|
||||
local persistant=
|
||||
local versionOrAlias=
|
||||
local alias=
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
if [[ $1 == "-p" || $1 == "-persistant" ]]; 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 kreFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
|
||||
local kreVersion=$(_kvm_package_version "$kreFullName")
|
||||
local kreFolder="$KRE_USER_PACKAGES/$kreFullName"
|
||||
local kreFile="$kreFolder/$kreFullName.nupkg"
|
||||
|
||||
if [ -e "$kreFolder" ]; then
|
||||
echo "$kreFullName already installed"
|
||||
else
|
||||
mkdir "$kreFolder" > /dev/null 2>&1
|
||||
cp -a "$versionOrAlias" "$kreFile"
|
||||
_kvm_unpack "$kreFile" "$kreFolder"
|
||||
[[ $? == 1 ]] && return 1
|
||||
fi
|
||||
kvm use "$kreVersion" "$persistent"
|
||||
[[ -n $alias ]] && kvm alias "$alias" "$kreVersion"
|
||||
else
|
||||
local kreFullName="$(_kvm_requested_version_or_alias $versionOrAlias)"
|
||||
local kreFolder="$KRE_USER_PACKAGES/$kreFullName"
|
||||
_kvm_download "$kreFullName" "$kreFolder"
|
||||
[[ $? == 1 ]] && return 1
|
||||
kvm use "$versionOrAlias" "$persistent"
|
||||
[[ -n $alias ]] && kvm alias "$alias" "$versionOrAlias"
|
||||
fi
|
||||
;;
|
||||
|
||||
"use" )
|
||||
[ $# -gt 3 ] && kvm help && return
|
||||
[ $# -lt 2 ] && kvm 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 KRE from process PATH"
|
||||
# Strip other version from PATH
|
||||
PATH=$(_kvm_strip_path "$PATH" "/bin")
|
||||
|
||||
if [[ -n $persistent && -e "$KRE_USER_HOME/alias/default.alias" ]]; then
|
||||
echo "Setting default KRE to none"
|
||||
rm "$KRE_USER_HOME/alias/default.alias"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
local kreFullName=$(_kvm_requested_version_or_alias "$versionOrAlias")
|
||||
local kreBin=$(_kvm_locate_kre_bin_from_full_name "$kreFullName")
|
||||
|
||||
if [[ -z $kreBin ]]; then
|
||||
echo "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Adding" $kreBin "to process PATH"
|
||||
|
||||
PATH=$(_kvm_strip_path "$PATH" "/bin")
|
||||
PATH=$(_kvm_prepend_path "$PATH" "$kreBin")
|
||||
|
||||
if [[ -n $persistent ]]; then
|
||||
local kreVersion=$(_kvm_package_version "$kreFullName")
|
||||
kvm alias default "$kreVersion"
|
||||
fi
|
||||
;;
|
||||
|
||||
"alias" )
|
||||
[[ $# -gt 3 ]] && kvm help && return
|
||||
|
||||
[[ ! -e "$KRE_USER_HOME/alias/" ]] && mkdir "$KRE_USER_HOME/alias/" > /dev/null
|
||||
|
||||
if [[ $# == 1 ]]; then
|
||||
echo ""
|
||||
local format="%-20s %s\n"
|
||||
printf "$format" "Alias" "Name"
|
||||
printf "$format" "-----" "----"
|
||||
for _kvm_file in $(find "$KRE_USER_HOME/alias" -name *.alias); do
|
||||
local alias="$(basename $_kvm_file | sed 's/.alias//')"
|
||||
local name="$(cat $_kvm_file)"
|
||||
printf "$format" "$alias" "$name"
|
||||
done
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
local name="$2"
|
||||
|
||||
if [[ $# == 2 ]]; then
|
||||
[[ ! -e "$KRE_USER_HOME/alias/$name.alias" ]] && echo "There is no alias called '$name'" && return
|
||||
cat "$KRE_USER_HOME/alias/$name.alias"
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
local kreFullName=$(_kvm_requested_version_or_alias "$3")
|
||||
|
||||
[[ ! -d "$KRE_USER_PACKAGES/$kreFullName" ]] && echo "$kreFullName is not an installed KRE version" && return 1
|
||||
|
||||
local action="Setting"
|
||||
[[ -e "$KRE_USER_HOME/alias/$name.alias" ]] && action="Updating"
|
||||
echo "$action alias '$name' to '$kreFullName'"
|
||||
echo "$kreFullName" > "$KRE_USER_HOME/alias/$name.alias"
|
||||
;;
|
||||
|
||||
"unalias" )
|
||||
[[ $# -ne 2 ]] && kvm help && return
|
||||
|
||||
local name=$2
|
||||
local aliasPath="$KRE_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 ]] && kvm help && return
|
||||
|
||||
[[ ! -d $KRE_USER_PACKAGES ]] && echo "KRE is not installed." && return 1
|
||||
|
||||
local searchGlob="KRE-*"
|
||||
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"
|
||||
for _kvm_file in $(find "$KRE_USER_HOME/alias" -name *.alias); do
|
||||
arr[$i]="$(basename $_kvm_file | sed 's/.alias//')/$(cat $_kvm_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 $KRE_USER_PACKAGES | sed s=$HOME=~=g)`
|
||||
for f in $(find $KRE_USER_PACKAGES -name "$searchGlob" -type d -prune -exec basename {} \;); do
|
||||
local active=""
|
||||
[[ $PATH == *"$KRE_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="KRE-$pkgName.$pkgVersion"
|
||||
temp2="KRE-$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
|
||||
}
|
||||
|
||||
kvm list default >/dev/null && kvm use default >/dev/null || true
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{{ProjectGuid}}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>{Name}</RootNamespace>
|
||||
<AssemblyName>{Name}</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<BaseIntermediateOutputPath>obj/net45</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\net45</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NET45;{Defines}</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>{ExtraProperties}
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\net45</OutputPath>
|
||||
<DefineConstants>TRACE;NET45;{Defines}</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>{ExtraProperties}
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
{References}
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
{Files}
|
||||
<Content Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
{ProjectReferences}
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
100
build/web.txt
100
build/web.txt
|
|
@ -1,100 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>
|
||||
</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{{ProjectGuid}}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>{Name}</RootNamespace>
|
||||
<AssemblyName>{Name}</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<IISExpressSSLPort />
|
||||
<IISExpressAnonymousAuthentication />
|
||||
<IISExpressWindowsAuthentication />
|
||||
<IISExpressUseClassicPipelineMode />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>obj\_\{TargetFramwork}</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;{TargetFramwork};{Defines}</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>obj\_\{TargetFramwork}</OutputPath>
|
||||
<DefineConstants>TRACE;{TargetFramwork};{Defines}</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>{ExtraProperties}
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
{References}
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
{Files}
|
||||
<Content Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
{ProjectReferences}
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
<None Include="Web.Release.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Web.config" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<UseIIS>True</UseIIS>
|
||||
<AutoAssignPort>True</AutoAssignPort>
|
||||
<DevelopmentServerPort>{Port}</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>http://localhost:{Port}/</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
</CustomServerUrl>
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<Target Name="BeforeBuild">
|
||||
<Copy SourceFiles="{AspNetLoaderPath}"
|
||||
DestinationFolder="{BinPath}"
|
||||
SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Loading…
Reference in New Issue