From 768cc595b1a659fd70ac46e352c23553eee48bb2 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Thu, 18 Sep 2014 17:48:50 -0700 Subject: [PATCH 1/9] Updated feed to release --- kvm.ps1 | 2 +- kvminstall.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kvm.ps1 b/kvm.ps1 index 834879a35a67..867737ca39f6 100644 --- a/kvm.ps1 +++ b/kvm.ps1 @@ -24,7 +24,7 @@ $feed = $env:KRE_NUGET_API_URL if (!$feed) { - $feed = "https://www.myget.org/F/aspnetvnext/api/v2"; + $feed = "https://www.myget.org/F/aspnetrelease/api/v2"; } $scriptPath = $myInvocation.MyCommand.Definition diff --git a/kvminstall.ps1 b/kvminstall.ps1 index 22c242262734..1b882f6bbeda 100644 --- a/kvminstall.ps1 +++ b/kvminstall.ps1 @@ -8,8 +8,8 @@ if (!(Test-Path $tempPath)) { md $tempPath | Out-Null } $webClient = New-Object System.Net.WebClient Write-Host "Downloading KVM.ps1 to $kvmPs1Path" -$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/master/kvm.ps1', $kvmPs1Path) +$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/release/kvm.ps1', $kvmPs1Path) Write-Host "Downloading KVM.cmd to $kvmCmdPath" -$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/master/kvm.cmd', $kvmCmdPath) +$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/release/kvm.cmd', $kvmCmdPath) Write-Host "Installing KVM" & $kvmCmdPath setup \ No newline at end of file From 0ffb0234e413e937dd0e9de2d25706adfb3f5696 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Thu, 30 Oct 2014 16:59:30 -0700 Subject: [PATCH 2/9] updated project.json and fix error in startup --- NuGet.Config | 2 +- samples/ConsoleApp/project.json | 4 ++-- samples/HelloMvc/Startup.cs | 2 +- samples/HelloMvc/project.json | 4 ++-- samples/HelloWeb/Startup.cs | 2 +- samples/HelloWeb/project.json | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NuGet.Config b/NuGet.Config index 600a375c7e4a..7d082f77c508 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -1,7 +1,7 @@  - + \ No newline at end of file diff --git a/samples/ConsoleApp/project.json b/samples/ConsoleApp/project.json index 4545d5367117..bf3278fb6d9e 100644 --- a/samples/ConsoleApp/project.json +++ b/samples/ConsoleApp/project.json @@ -3,7 +3,7 @@ "System.Console": "4.0.0.0" }, "frameworks": { - "net45": {}, - "k10": {} + "aspnet50": {}, + "aspnetcore50": {} } } \ No newline at end of file diff --git a/samples/HelloMvc/Startup.cs b/samples/HelloMvc/Startup.cs index cbe4bc4f59ca..eb17e8a18c8e 100644 --- a/samples/HelloMvc/Startup.cs +++ b/samples/HelloMvc/Startup.cs @@ -6,7 +6,7 @@ namespace HelloMvc { public class Startup { - public void Configure(IBuilder app) + public void Configure(IApplicationBuilder app) { app.UseErrorPage(); diff --git a/samples/HelloMvc/project.json b/samples/HelloMvc/project.json index 2fe4a51df85a..6dee13b65f90 100644 --- a/samples/HelloMvc/project.json +++ b/samples/HelloMvc/project.json @@ -12,7 +12,7 @@ "Kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004" }, "frameworks": { - "net45": {}, - "k10": {} + "aspnet50": {}, + "aspnetcore50": {} } } \ No newline at end of file diff --git a/samples/HelloWeb/Startup.cs b/samples/HelloWeb/Startup.cs index 96e399e2efa5..b41f459f03d7 100644 --- a/samples/HelloWeb/Startup.cs +++ b/samples/HelloWeb/Startup.cs @@ -4,7 +4,7 @@ namespace KWebStartup { public class Startup { - public void Configure(IBuilder app) + public void Configure(IApplicationBuilder app) { app.UseStaticFiles(); app.UseWelcomePage(); diff --git a/samples/HelloWeb/project.json b/samples/HelloWeb/project.json index 45c3e666e0e3..69dc29621381 100644 --- a/samples/HelloWeb/project.json +++ b/samples/HelloWeb/project.json @@ -12,7 +12,7 @@ "Kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004" }, "frameworks": { - "net45": {}, - "k10": {} + "aspnet50": {}, + "aspnetcore50": {} } } \ No newline at end of file From acb8eddd49df7a31270c0c72cf24166c0c6e0c55 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Tue, 4 Nov 2014 14:41:27 -0800 Subject: [PATCH 3/9] updated consoleapp project.json --- samples/ConsoleApp/project.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/ConsoleApp/project.json b/samples/ConsoleApp/project.json index bf3278fb6d9e..842362bdf571 100644 --- a/samples/ConsoleApp/project.json +++ b/samples/ConsoleApp/project.json @@ -1,9 +1,13 @@ { "dependencies": { - "System.Console": "4.0.0.0" + }, "frameworks": { "aspnet50": {}, - "aspnetcore50": {} + "aspnetcore50": { + "dependencies": { + "System.Console": "4.0.0-*" + } +} } } \ No newline at end of file From 1234f3dc199b56ec84e835347551f894a30368bd Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Tue, 4 Nov 2014 14:44:29 -0800 Subject: [PATCH 4/9] fix for kvm.ps1 --- kvm.ps1 | 1375 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 743 insertions(+), 632 deletions(-) diff --git a/kvm.ps1 b/kvm.ps1 index 867737ca39f6..8983061037a4 100644 --- a/kvm.ps1 +++ b/kvm.ps1 @@ -1,634 +1,745 @@ -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, - [switch] $x86 = $false, - [switch] $x64 = $false, - [switch] $svr50 = $false, - [switch] $svrc50 = $false, - [alias("a")] - [string] $alias = $null, - [parameter(Position=1, ValueFromRemainingArguments=$true)] - [string[]]$args=@() -) - -$userKrePath = $env:USERPROFILE + "\.kre" -$userKrePackages = $userKrePath + "\packages" -$globalKrePath = $env:ProgramFiles + "\KRE" -$globalKrePackages = $globalKrePath + "\packages" -$feed = $env:KRE_NUGET_API_URL - -if (!$feed) -{ - $feed = "https://www.myget.org/F/aspnetrelease/api/v2"; -} - -$scriptPath = $myInvocation.MyCommand.Definition - -function Kvm-Help { -@" -K Runtime Environment Version Manager - Build 10002 - -USAGE: kvm [options] - -kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy
] - 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
use given address as proxy when accessing remote server - -kvm install |||latest [-x86][-x64] [-svr50][-svrc50] [-a|-alias ] [-g|-global] [-f|-force] - | install requested KRE from feed - 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 set alias for requested KRE on install - -g|-global install to machine-wide location - -f|-force install even if specified version is already installed - -kvm use ||none [-x86][-x64] [-svr50][-svrc50] [-p|-persistent] [-g|-global] - | 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 - display value of named alias - -kvm alias | [-x86][-x64] [-svr50][-svrc50] - The name of the alias to set - | The KRE version to set the alias to. Alternatively use the version of the specified alias - -"@ | Write-Host -} - -function Kvm-Global-Setup { - If (Needs-Elevation) - { - $arguments = "& '$scriptPath' setup $(Requested-Switches) -persistent" - Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait - Write-Host "Setup complete" - Kvm-Help - break - } - - $scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath) - - $kvmBinPath = "$userKrePath\bin" - - 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) - - Write-Host "Press any key to continue ..." - $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC") -} - -function Kvm-Global-Upgrade { - $persistent = $true - $alias="default" - If (Needs-Elevation) { - $arguments = "& '$scriptPath' upgrade -global $(Requested-Switches)" - Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait - break - } - Kvm-Global-Install "latest" -} - -function Kvm-Upgrade { - $persistent = $true - $alias="default" - Kvm-Install "latest" -} - -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 - - 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 -} - -function Do-Kvm-Unpack { -param( - [string] $kreFile, - [string] $kreFolder -) - Write-Host "Unpacking to" $kreFolder - 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 - } - - 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-Global-Install { -param( - [string] $versionOrAlias -) - If (Needs-Elevation) { - $arguments = "& '$scriptPath' install -global $versionOrAlias $(Requested-Switches)" - Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait - Kvm-Global-Use $versionOrAlias - break - } - - if ($versionOrAlias -eq "latest") { - $versionOrAlias = Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86") - } - - $kreFullName = Requested-VersionOrAlias $versionOrAlias - - Do-Kvm-Download $kreFullName $globalKrePackages - Kvm-Use $versionOrAlias - if (![string]::IsNullOrWhiteSpace($alias)) { - Kvm-Alias-Set $alias $versionOrAlias - } -} - -function Kvm-Install { -param( - [string] $versionOrAlias -) - if ($versionOrAlias.EndsWith(".nupkg")) - { - $kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias) - $kreFolder = "$userKrePackages\$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 $userKrePackages "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 - } - - $packageVersion = Package-Version $kreFullName - Kvm-Use $packageVersion - if (![string]::IsNullOrWhiteSpace($alias)) { - Kvm-Alias-Set $alias $packageVersion - } +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, + [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/aspnetrelease/api/v2"; +} + +$scriptPath = $myInvocation.MyCommand.Definition + +function Kvm-Help { +@" +K Runtime Environment Version Manager - Build 10017 + +USAGE: kvm [options] + +kvm upgrade [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-g|-global] [-f|-force] [-proxy
] + 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
use given address as proxy when accessing remote server + +kvm install |||latest [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-a|-alias ] [-g|-global] [-f|-force] + | install requested KRE from feed + 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 set alias for requested KRE on install + -g|-global install to machine-wide location + -f|-force install even if specified version is already installed + +kvm use ||none [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-p|-persistent] [-g|-global] + | 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 + display value of the specified alias + +kvm alias | [-x86][-amd64] [-r|-runtime CLR|CoreCLR] + The name of the alias to set + | The KRE version to set the alias to. Alternatively use the version of the specified alias + +kvm unalias + 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) } - else + $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) { - if ($versionOrAlias -eq "latest") { - $versionOrAlias = Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86") - } - $kreFullName = Requested-VersionOrAlias $versionOrAlias - - Do-Kvm-Download $kreFullName $userKrePackages - Kvm-Use $versionOrAlias - if (![string]::IsNullOrWhiteSpace($alias)) { - Kvm-Alias-Set $alias $versionOrAlias - } - } -} - -function Kvm-List { - $kreHome = $env:KRE_HOME - if (!$kreHome) { - $kreHome = $env:ProgramFiles + "\KRE;%USERPROFILE%\.kre" - } - $items = @() - foreach($portion in $kreHome.Split(';')) { - $path = [System.Environment]::ExpandEnvironmentVariables($portion) - if (Test-Path("$path\packages")) { - $items += Get-ChildItem ("$path\packages\KRE-*") | List-Parts - } - } - $items | Sort-Object Version, Runtime, Architecture | Format-Table -AutoSize -Property @{name="Active";expression={$_.Active};alignment="center"}, "Version", "Runtime", "Architecture", "Location" -} - -filter List-Parts { - $hasBin = Test-Path($_.FullName+"\bin") - if (!$hasBin) { - return - } - $active = $false - foreach($portion in $env:Path.Split(';')) { - if ($portion.StartsWith($_.FullName)) { - $active = $true - } - } - $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 - } -} - -function Kvm-Global-Use { -param( - [string] $versionOrAlias -) - If (Needs-Elevation) { - $arguments = "& '$scriptPath' use -global $versionOrAlias $(Requested-Switches)" - if ($persistent) { - $arguments = $arguments + " -persistent" - } - Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait - break - } - - 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 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) { - 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)) - - 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-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) { - 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)) - - 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 - - Write-Host "Setting alias '$name' to '$kreFullName'" - md ($userKrePath + "\alias\") -Force | Out-Null - $kreFullName | Out-File ($userKrePath + "\alias\" + $name + ".txt") ascii -} - -function Locate-KreBinFromFullName() { -param( - [string] $kreFullName -) - $kreHome = $env:KRE_HOME - if (!$kreHome) { - $kreHome = $env:ProgramFiles + ";%USERPROFILE%\.kre" - } - 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 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 "svr50" - $pkgArchitecture = Requested-Architecture "x86" - } - return "KRE-" + $pkgPlatform + "-" + $pkgArchitecture + "." + $pkgVersion -} - -function Requested-Platform() { -param( - [string] $default -) - if ($svr50 -and $svrc50) { - Throw "This command cannot accept both -svr50 and -svrc50" - } - if ($svr50) { - return "svr50" - } - if ($svrc50) { - return "svrc50" - } - return $default -} - -function Requested-Architecture() { -param( - [string] $default -) - if ($x86 -and $x64) { - Throw "This command cannot accept both -x86 and -x64" - } - if ($x86) { - return "x86" - } - if ($x64) { - return "x64" - } - 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 ($x64) {$arguments = "$arguments -x64"} - if ($svr50) {$arguments = "$arguments -svr50"} - if ($svrc50) {$arguments = "$arguments -svrc50"} - return $arguments -} - - try { - if ($global) { - switch -wildcard ($command + " " + $args.Count) { - "setup 0" {Kvm-Global-Setup} - "upgrade 0" {Kvm-Global-Upgrade} - "install 1" {Kvm-Global-Install $args[0]} -# "list 0" {Kvm-Global-List} - "use 1" {Kvm-Global-Use $args[0]} - default {Write-Host 'Unknown command, or global switch not supported'; Kvm-Help;} - } - } else { - switch -wildcard ($command + " " + $args.Count) { - "setup 0" {Kvm-Global-Setup} - "upgrade 0" {Kvm-Upgrade} - "install 1" {Kvm-Install $args[0]} - "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]} - "help 0" {Kvm-Help} - " 0" {Kvm-Help} - default {Write-Host 'Unknown command'; Kvm-Help;} - } - } - } - catch { - Write-Host $_ -ForegroundColor Red ; - } + 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 + 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 + } + + 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 + } + } +} + +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) { + Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?" + return + } + + 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) { + 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)) + + 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 + } +} + +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-Host $_ -ForegroundColor Red ; + Write-Host "Type 'kvm help' for help on how to use kvm." +} +if ($wait) { + Write-Host "Press any key to continue ..." + $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC") +} From 531cbbb817a45f5e2955ba3aa2b38976d45f934d Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Wed, 5 Nov 2014 13:31:19 -0800 Subject: [PATCH 5/9] updated system.console pkg version --- samples/ConsoleApp/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/ConsoleApp/project.json b/samples/ConsoleApp/project.json index 842362bdf571..9c297e5bc9f4 100644 --- a/samples/ConsoleApp/project.json +++ b/samples/ConsoleApp/project.json @@ -6,7 +6,7 @@ "aspnet50": {}, "aspnetcore50": { "dependencies": { - "System.Console": "4.0.0-*" + "System.Console": "4.0.0-beta-*" } } } From 7b55520208b8902bd51f9a388e146ee6ad485061 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Tue, 11 Nov 2014 17:36:53 -0800 Subject: [PATCH 6/9] Change to release bits to push in master --- README.md | 176 ++++++++++++++++++++++++------------------------- kvm.ps1 | 2 +- kvm.sh | 2 +- kvminstall.ps1 | 4 +- 4 files changed, 89 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 0913e8804e1f..1d5e107609e4 100644 --- a/README.md +++ b/README.md @@ -1,144 +1,138 @@ # ASP.NET vNext Home +Latest dev version: [![dev version](http://img.shields.io/myget/aspnetvnext/v/KRE-CLR-x86.svg?style=flat)](https://www.myget.org/gallery/aspnetvnext)
+Latest master version: [![master version](http://img.shields.io/myget/aspnetmaster/v/KRE-CLR-x86.svg?style=flat)](https://www.myget.org/gallery/aspnetmaster) -In the next version of ASP.NET we are working with multiple teams around Microsoft to create a lean, composable .NET stack that provides a familiar and modern framework for web and cloud scenarios. +The Home repository is the starting point for people to learn about ASP.NET vNext. This repo contains samples and [documentation](https://github.com/aspnet/Home/wiki) to help folks get started and learn more about what's coming in ASP.NET vNext. -The Home repository is the starting point for people to learn about ASP.NET vNext, it contains samples and [documentation](https://github.com/aspnet/Home/wiki) to help folks get started and learn more about what we are doing. +ASP.NET vNext is being actively developed by the ASP.NET team assigned to the Microsoft Open Tech Hub and in collaboration with a community of open source developers. Together we are dedicated to creating the best possible platform for web development. -These products are actively developed by the ASP.NET team assigned to the Microsoft Open Tech Hub and in collaboration with a community of open source developers. Together we are dedicated to creating the best possible platform for web development. +The samples provided in this repo are designed to show some of the features of the new framework and to provide a starting point for further exploration. All the component packages are available on Nuget. To try out the latest bits under development switch to the dev branch of the Home repo and use the dev feed in Nuget.config (https://www.myget.org/F/aspnetvnext). -The samples provided are designed to show some of the features of the new framework as well as setting up a sandbox for you to try out some of the new features. The NuGet.config file in the repo points to a MyGet feed (https://www.myget.org/F/aspnetvnext/) that has all the packages being developed. The feed is updated every time a full build succeeds. +## Contents +* [Minimum Requirements](#minimum-requirements) +* [Getting Started](#getting-started) +* [Samples](#samples) +* [Documentation and Further Learning](#documentation-and-further-learning) +* [Repos and Projects](#repos-and-projects) +* [Feedback](#feedback) -# Minimum Requirements +## Minimum Requirements -These are the current minimum requirements, they do not necesarilly represent our RTM minimum. +These are the current minimum requirements for the latest preview release. They do not necessarily represent what the final minimum requirements will be. ### Windows -* Windows 7 or greater, though Core CLR will only work on Windows 8 today. If using Core CLR you will need to be on Windows 8 or above. At RTM the whole stack will support Windows 7+ and Windows Server 2008 R2+. +* Windows 7 or Windows Server 2008 R2. * .NET 4.5.1 for hosting in IIS -### OSX/Linux - * Mono >= 3.4.1 - Currently this means compiling Mono from source from https://github.com/mono/mono (Note: See instructions below to install the Homebrew formula that can install the required mono) - * On Linux, you may need to run `mozroots --import --sync` after installing mono +### OS X/Linux + * Mono 3.4.1 or later (Note: On OS X use the Homebrew formula specified below to install the required version of Mono) * bash or zsh and curl -#Getting Started +## Getting Started -The first thing we need to do is setup the tools required to build and run an application. We will start out by getting the [K Version Manager (KVM)](https://github.com/aspnet/Home/wiki/version-manager) +The easiest way to get started with ASP.NET vNext is to try out the latest preview of Visual Studio 2015 Preview. You can find installation instructions and getting started documentation at http://www.asp.net/vnext. -The easiest way to get the KVM on Windows is to run the following command: -```powershell -@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1'))" -``` -or on OSX: +That said, you can also try out ASP.NET vNext with just a command-prompt and a text editor. The following instructions will walk you through getting your dev environment setup. + +### Install the K Version Manager (KVM) + +The first thing we need to do is setup the tools required to build and run an application. We will start out by getting the [K Version Manager (KVM)](https://github.com/aspnet/Home/wiki/version-manager). You use the K Version Manager to install different versions of the ASP.NET vNext runtime and switch between them. + +#### Windows +To install KVM on Windows run the following command, which will download and run a script that installs KVM for the current user (requires admin privileges): + +*@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1'))"* + +After the script has run open a new command prompt to start using KVM. -Mono and KVM (K Version manager) required to develop & run next generation ASP.NET applications on OSX is available as a Homebrew formula. To install the necessary development tools: +#### OS X: - * Open a terminal on your MAC - * Install [Homebrew](http://brew.sh) by running the following command. If you already have Homebrew installed skip this step. -```ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"``` - * Run command `brew tap aspnet/k` to tap the aspnet vnext related git repositories. - * Run command `brew install kvm` to install KVM. This also automatically install the latest KRE package from https://www.myget.org/f/aspnetvnext/api/v2 feed. +To install KVM and the correct version of Mono on OS X using [Homebrew](http://brew.sh) follow the following steps: -Now you are set for developing next general ASP.NET applications on OSX. A few things to note: - * If you would like to use a different KRE version for your development, you can install the desired version using KVM. See [KVM page](https://github.com/aspnet/Home/wiki/version-manager) for more information. + * Install [Homebrew](http://brew.sh) if it is not already installed. + * Run command `brew tap aspnet/k` to tap the ASP.NET vNext related git repositories. If you had already tapped the repo for previous releases, run `brew untap aspnet/k` to delete the old commands and tap again to get the updated brew scripts. + * Run command `brew install kvm` to install KVM. This also automatically install the latest KRE package from https://www.myget.org/f/aspnetmaster/api/v2 feed. * Run command `source kvm.sh` on your terminal if your terminal cannot understand kvm. -or on Linux: +#### Linux: + +To install KVM on Linux run the following command: + ``` curl https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh && source ~/.kre/kvm/kvm.sh ``` -This downloads KVM from this repository and puts it on your machine. Alternatively, you you could clone the repo and get it: -* Clone the repository -* On the command line execute - * ```kvm setup``` on Windows or - * ```sh kvminstall.sh && source ~/.kre/kvm/kvm.sh``` on OSX/Linux - -This command will setup your environment, getting it ready to install a version of the runtime. It adds KVM to your path and puts it in your user profile. Once you have KVM then you need to get a version of the runtime: -* Execute ```kvm install 0.1-alpha-build-0446```. This command will download the named version of the KRE and put it on your user profile ready to use. You can get the latest version by running ```kvm upgrade``` but 0446 was the last version explicitly tested. see the [KVM page](https://github.com/aspnet/Home/wiki/version-manager) for more information on KVM. -* Navigate to samples\ConsoleApp -* Run ```kpm restore```. This downloads the System.Console package so the app can do Console.WriteLine -* Run ```k run``` -* You should see a message saying "Hello World" -* Type - * ```SET KRE_TRACE=1``` on Windows or - * ```export KRE_TRACE=1``` on OSX/Linux -* Run ```k run``` -* You should now see compiler output as well as the "Hello World" message +Note that on Linux you need to also install [Mono](http://mono-project.com) 3.4.1 or later. -``` -:: getting started -git clone https://github.com/aspnet/Home.git -cd Home -kvm setup -kvm install 0.1-alpha-build-0446 -p - -cd samples\ConsoleApp -kpm restore -k run - -SET KRE_TRACE=1 -k run -``` +### Install the K Runtime Environment (KRE) -# Samples +Now that you have KVM setup you can install the latest version of the runtime by running the following command: ```kvm upgrade``` + +This command will download the specified version of the K Runtime Environment (KRE), and put it on your user profile ready to use. You are now ready to start using ASP.NET vNext! -## Sandbox Samples +## Samples -These samples, in this repo, are just basic starting points for you to experiment with features. Since there is no File->New Project we thought some simple samples to take the place of scaffolding would be convenient. +The samples in this repo are basic starting points for you to experiment with. + [ConsoleApp](https://github.com/aspnet/Home/tree/master/samples/ConsoleApp). This is just basic console app if you want to use it as a starting point. + [HelloWeb](https://github.com/aspnet/Home/tree/master/samples/HelloWeb). This is a minimal startup class that shows welcome page and static file middleware. This is mostly for you to run through the steps in the readme and make sure you have everything setup and working correctly. + [HelloMvc](https://github.com/aspnet/Home/tree/master/samples/HelloMvc). This sample is a basic MVC app. It is not designed to show all the functionality of the new web stack, but to give you a starting point to play with features. ++ [MVC Music Store](https://github.com/aspnet/MusicStore) and [BugTracker](https://github.com/aspnet/BugTracker) are application samples that are both being ported to ASP.NET vNext. Each of these samples have their own separate repositories that you can look at. -**NOTE: The samples are pinned to a specific version of the packages. If you want to try the latest builds then update the project.json and replace the last part of the version with a '\*', so '0.1-alpha-build-267' becomes '0.1-alpha-\*', and then run ```kpm restore``` to pull down the latest packages** +### Running the samples -## Feature Samples -The [Entropy repo](https://github.com/aspnet/Entropy) contains samples of specific features in isolation. Each directory contains just enough code to show an aspect of a feature. +1. Clone the Home repository +2. Change directory to the folder of the sample you want to run +3. Run ```kpm restore``` to restore the packages required by that sample. +4. You should see a bunch of output as all the dependencies of the app are downloaded from MyGet. +5. Run the sample using the appropriate K command: + - For the console app run ```k run```. + - For the web apps run ```k web``` on Windows or ```k kestrel``` on Mono. +6. You should see the output of the console app or a message that says the site is now started. +7. You can navigate to the web apps in a browser by going to "http://localhost:5001" or "http://localhost:5004" if running on Mono. -## Application Samples -[MVC Music Store](https://github.com/aspnet/MusicStore) and [BugTracker](https://github.com/aspnet/BugTracker) application are both being ported. Each of these have their own repository that you can look at. +### Switching to Core CLR -# Running the samples +By default when running ASP.NET vNext applications on the Windows platform you are running on the full .NET Framework. You can switch to use the new Cloud Optimized runtime, or Core CLR, using the KVM command. -## Running HelloWeb +1. Run ```kvm upgrade -runtime CoreCLR``` This command gets the latest Core CLR version of the k runtime and sets it as your default. The `-runtime CoreCLR` switch tells it to use Core CLR. You can use `-r CLR` to target desktop again. +2. Run ```k web``` to run on WebListener. +3. The first line of your output should say "Loaded Module: klr.core45.dll" instead of "Loaded Module: klr.net45.dll" +4. The HelloWeb app should work the same as when running on the full desktop .NET Framework but now as a fully self-contained app with true side-by-side versioning support. -1. Clone the repository -2. Change directory to Samples\HelloWeb -3. Run ```kpm restore``` -4. You should see a bunch of output as all the dependencies of the app are downloaded from MyGet. The K commands all operate on the app that is in the current directory. -5. Run ```K web``` to run on WebListener. Or run ```K Kestrel``` to run on Mono. -6. You should see build output and a message to show the site is now started -7. Navigate to "http://localhost:5001" or "http://localhost:5004" in case of Mono -8. You should see the welcome page -9. Navigate to "http://localhost:5001/image.jpg" or "http://localhost:5004/image.img" in case of Mono. -10. You should see an image served with the static file middleware +**NOTE: There are many APIs from the .NET Framework that are not yet available when running on Core CLR. This set should get smaller and smaller as time goes on.** -If you can do all of the above then everything should be working. You can try out the WebFx sample now to see some more of the new stack. You should run ```kpm restore``` before using any sample for the first time. +**NOTE: There is no Core CLR currently available on OSX/Linux. There is only a single platform (mono45) and a single architecture (x86).** -# Switching to Core CLR +## Documentation and Further Learning +### [Community Standup](http://www.youtube.com/playlist?list=PL0M0zPgJ3HSftTAAHttA3JQU4vOjXFquF) +The community standup is held every week and streamed live to YouTube. You can view past standups in the linked playlist. -By default when running the applications you are running against Desktop CLR (4.5), you can change that using the KVM command. +If you have questions you can also jump online during the next standup and have them answered live. -1. Run ```kvm install 0.1-alpha-build-0446 -svrc50``` This command gets the latest Core CLR version of the k runtime and sets it as your default. The -svrc50 switch tells it to use Core CLR, you can use -svr50 to target desktop again. -2. Run ```K web``` to run on WebListener. Or run ```K Kestrel``` to run on Mono. -3. The first line of your output should say "Loaded Module: klr.core45.dll" instead of "Loaded Module: klr.net45.dll" -4. The HelloWeb app should work the same as when running on Desktop CLR. +### [Wiki Documentation] (https://github.com/aspnet/Home/wiki) +We have some useful documentation on the wiki of this Repo. This wiki is a central spot for docs from any part of the stack. -**NOTE: There are going to be parts of the stack that work on Desktop but do not work on Core CLR. This set should get smaller and smaller as time goes on, but it is entirely likely as you use Core CLR you will hit errors that can't be worked around as the Core CLR surface area just does not exist yet.** +If you see errors, or want some extra content, then feel free to create an issue or send a pull request (see feedback section below). -**NOTE: There is no Core CLR currently on OSX/Linux. There is only a single platform (mono45) and a single architecture (x86).** +### [ASP.NET/vNext](http://www.asp.net/vnext) +The vNext page on the ASP.NET site has links to some TechEd videos and articles with some good information about vNext. -#Core CLR Packages +## Repos and Projects -Currently the BCL is split into some fairly fine grained packages, which was one of the goals of this effort. However, the packages that exist today do not necessarily represent the list of packages that we will end up with. We are still experimenting with what makes sense to be a package and what the experience should be. +These are some of the most common repos: -# Known Issues +* [DependencyInjection](https://github.com/aspnet/DependencyInjection) - basic dependency injection infrastructure and default implementation +* [EntityFramework](https://github.com/aspnet/EntityFramework) - data access technology +* [Identity](https://github.com/aspnet/Identity) - users and membership system +* [KRuntime](https://github.com/aspnet/KRuntime) - core runtime, project system, loader +* [MVC](https://github.com/aspnet/Mvc) - MVC framework for web apps and services +* [SignalR-Server](https://github.com/aspnet/SignalR-Server) - real-time -* Core CLR doesn't currently work on Windows OSes earlier than Windows 8 +A description of all the repos is [here](https://github.com/aspnet/Home/wiki/Repo-List). -# Feedback +## Feedback Check out the [contributing](https://github.com/aspnet/Home/blob/master/CONTRIBUTING.md) page to see the best places to log issues and start discussions. diff --git a/kvm.ps1 b/kvm.ps1 index 8983061037a4..c38bfa7c76d0 100644 --- a/kvm.ps1 +++ b/kvm.ps1 @@ -38,7 +38,7 @@ function String-IsEmptyOrWhitespace([string]$str) { if (!$feed) { - $feed = "https://www.myget.org/F/aspnetrelease/api/v2"; + $feed = "https://www.myget.org/F/aspnetmaster/api/v2"; } $scriptPath = $myInvocation.MyCommand.Definition diff --git a/kvm.sh b/kvm.sh index c9a91055b539..3c5749d074c2 100644 --- a/kvm.sh +++ b/kvm.sh @@ -18,7 +18,7 @@ KRE_MONO45= KRE_X86= KRE_X64= if [ -z "$KRE_FEED" ]; then - KRE_FEED="https://www.myget.org/F/aspnetvnext/api/v2" + KRE_FEED="https://www.myget.org/F/aspnetmaster/api/v2" fi _kvm_find_latest() { diff --git a/kvminstall.ps1 b/kvminstall.ps1 index 1b882f6bbeda..22c242262734 100644 --- a/kvminstall.ps1 +++ b/kvminstall.ps1 @@ -8,8 +8,8 @@ if (!(Test-Path $tempPath)) { md $tempPath | Out-Null } $webClient = New-Object System.Net.WebClient Write-Host "Downloading KVM.ps1 to $kvmPs1Path" -$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/release/kvm.ps1', $kvmPs1Path) +$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/master/kvm.ps1', $kvmPs1Path) Write-Host "Downloading KVM.cmd to $kvmCmdPath" -$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/release/kvm.cmd', $kvmCmdPath) +$webClient.DownloadFile('https://raw.githubusercontent.com/aspnet/Home/master/kvm.cmd', $kvmCmdPath) Write-Host "Installing KVM" & $kvmCmdPath setup \ No newline at end of file From 0dfa67a9a740cd9da643ef51764d8b00296e36a6 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Tue, 11 Nov 2014 17:39:53 -0800 Subject: [PATCH 7/9] Deleting Nuget.config file --- NuGet.Config | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 NuGet.Config diff --git a/NuGet.Config b/NuGet.Config deleted file mode 100644 index 7d082f77c508..000000000000 --- a/NuGet.Config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file From d6e3bf2b23d6a93b59ceaf20d5e203a74ee0e43d Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Tue, 11 Nov 2014 21:34:15 -0800 Subject: [PATCH 8/9] Updated right kvm.sh and link in readme --- README.md | 2 +- kvm.sh | 100 ++++++++++++++++++++++++++++++++---------------------- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 1d5e107609e4..3d2e50a04b76 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ To install KVM and the correct version of Mono on OS X using [Homebrew](http://b * Install [Homebrew](http://brew.sh) if it is not already installed. * Run command `brew tap aspnet/k` to tap the ASP.NET vNext related git repositories. If you had already tapped the repo for previous releases, run `brew untap aspnet/k` to delete the old commands and tap again to get the updated brew scripts. - * Run command `brew install kvm` to install KVM. This also automatically install the latest KRE package from https://www.myget.org/f/aspnetmaster/api/v2 feed. + * Run command `brew install kvm` to install KVM. This also automatically install the latest KRE package from https://www.nuget.org/api/v2 feed. * Run command `source kvm.sh` on your terminal if your terminal cannot understand kvm. #### Linux: diff --git a/kvm.sh b/kvm.sh index 3c5749d074c2..8bea06f98604 100644 --- a/kvm.sh +++ b/kvm.sh @@ -14,23 +14,19 @@ if [ -z "$KRE_USER_HOME" ]; then fi KRE_USER_PACKAGES="$KRE_USER_HOME/packages" -KRE_MONO45= -KRE_X86= -KRE_X64= if [ -z "$KRE_FEED" ]; then KRE_FEED="https://www.myget.org/F/aspnetmaster/api/v2" fi _kvm_find_latest() { - local platform="mono45" - local architecture="x86" + 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-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false" + 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/')" @@ -61,7 +57,7 @@ _kvm_package_name() { _kvm_package_runtime() { local kreFullName="$1" - echo "$kreFullName" | sed "s/KRE-\([^-]*\).*/\1/" + echo "$kreFullName" | sed "s/KRE-\([^.-]*\).*/\1/" } _kvm_download() { @@ -93,6 +89,7 @@ _kvm_download() { [[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $kreFullName from $KRE_FEED" && return 1 _kvm_unpack $kreFile $kreFolder + return $? } _kvm_unpack() { @@ -119,23 +116,6 @@ _kvm_unpack() { -exec sh -c "head -c 11 {} | grep '/bin/bash' > /dev/null" \; -print | xargs chmod 775 } -# This is not currently required. Placeholder for the case when we have multiple platforms (ie if we bundle mono) -_kvm_requested_platform() { - local default=$1 - [[ -z $KRE_MONO45 ]] && echo "mono45" && return - echo $default -} - -# This is not currently required. Placeholder for the case where we have multiple architectures (ie if we bundle mono) -_kvm_requested_architecture() { - local default=$1 - - [[ -n $KRE_X86 && -n $KRE_X64 ]] && echo "This command cannot accept both -x86 and -x64" && return 1 - [[ -z $KRE_X86 ]] && echo "x86" && return - [[ -z $KRE_X64 ]] && echo "x64" && return - echo $default -} - _kvm_requested_version_or_alias() { local versionOrAlias="$1" @@ -143,14 +123,13 @@ _kvm_requested_version_or_alias() { 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=$(_kvm_requested_platform $(echo "$pkgName" | sed "s/KRE-\([^-]*\).*/\1/")) - local pkgArchitecture=$(_kvm_requested_architecture $(echo "$pkgName" | sed "s/.*-.*-\([^-]*\).*/\1/")) + local pkgPlatform=$(echo "$pkgName" | sed "s/KRE-\([^.-]*\).*/\1/") else local pkgVersion=$versionOrAlias - local pkgPlatform=$(_kvm_requested_platform "mono45") - local pkgArchitecture=$(_kvm_requested_architecture "x86") + local pkgPlatform="Mono" fi - echo "KRE-$pkgPlatform-$pkgArchitecture.$pkgVersion" + + echo "KRE-$pkgPlatform.$pkgVersion" } # This will be more relevant if we support global installs @@ -169,7 +148,7 @@ kvm() case $1 in "help" ) echo "" - echo "K Runtime Environment Version Manager - Build 10002" + echo "K Runtime Environment Version Manager - Build 10017" echo "" echo "USAGE: kvm [options]" echo "" @@ -198,12 +177,14 @@ kvm() echo "list KRE aliases which have been defined" echo "" echo "kvm alias " - echo "display value of named alias" + echo "display value of the specified alias" echo "" echo "kvm alias " echo " The name of the alias to set" echo "| The KRE version to set the alias to. Alternatively use the version of the specified alias" echo "" + echo "kvm unalias " + echo "remove the specified alias" echo "" ;; @@ -233,7 +214,7 @@ kvm() done if [[ "$versionOrAlias" == "latest" ]]; then echo "Determining latest version" - versionOrAlias=$(_kvm_find_latest mono45 x86) + versionOrAlias=$(_kvm_find_latest) [[ $? == 1 ]] && echo "Error: Could not find latest version from feed $KRE_FEED" && return 1 echo "Latest version is $versionOrAlias" fi @@ -249,6 +230,7 @@ kvm() 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" @@ -256,7 +238,7 @@ kvm() local kreFullName="$(_kvm_requested_version_or_alias $versionOrAlias)" local kreFolder="$KRE_USER_PACKAGES/$kreFullName" _kvm_download "$kreFullName" "$kreFolder" - [[ $? == 1 ]] && return + [[ $? == 1 ]] && return 1 kvm use "$versionOrAlias" "$persistent" [[ -n $alias ]] && kvm alias "$alias" "$versionOrAlias" fi @@ -339,12 +321,23 @@ kvm() local kreFullName=$(_kvm_requested_version_or_alias "$3") - [[ ! -d "$KRE_USER_PACKAGES/$kreFullName" ]] && echo "$kreFullName is not an installed KRE version." && return 1 - - echo "Setting alias '$name' to '$kreFullName'" + [[ ! -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 @@ -357,15 +350,38 @@ kvm() local searchGlob=$(_kvm_requested_version_or_alias "$versionOrAlias") fi echo "" - local formatString="%-6s %-20s %-7s %-12s %s\n" - printf "$formatString" "Active" "Version" "Runtime" "Architecture" "Location" - printf "$formatString" "------" "-------" "-------" "------------" "--------" + + local arr=() + local i=0 + 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") - printf "$formatString" "$active" "$pkgVersion" "$pkgName" "x86" "$KRE_USER_PACKAGES" + + 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 @@ -377,6 +393,8 @@ kvm() echo "Unknown command $1" return 1 esac + + return 0 } -kvm list default >/dev/null && kvm use default >/dev/null || true +kvm list default >/dev/null && kvm use default >/dev/null || true \ No newline at end of file From c6679009a1492be81ca5c54b2fd9c028e491929d Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Wed, 12 Nov 2014 07:25:41 -0800 Subject: [PATCH 9/9] Changing feeds to point to nuget --- kvm.ps1 | 2 +- kvm.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kvm.ps1 b/kvm.ps1 index c38bfa7c76d0..9d38c219691c 100644 --- a/kvm.ps1 +++ b/kvm.ps1 @@ -38,7 +38,7 @@ function String-IsEmptyOrWhitespace([string]$str) { if (!$feed) { - $feed = "https://www.myget.org/F/aspnetmaster/api/v2"; + $feed = "https://www.nuget.org/api/v2"; } $scriptPath = $myInvocation.MyCommand.Definition diff --git a/kvm.sh b/kvm.sh index 8bea06f98604..c34a87bc2c52 100644 --- a/kvm.sh +++ b/kvm.sh @@ -15,7 +15,7 @@ fi KRE_USER_PACKAGES="$KRE_USER_HOME/packages" if [ -z "$KRE_FEED" ]; then - KRE_FEED="https://www.myget.org/F/aspnetmaster/api/v2" + KRE_FEED="https://www.nuget.org/api/v2" fi _kvm_find_latest() {