Update KVM to newer build, update Readme to show how to use KVMInstall. Pipe md to out-null when creating temp directory.

This commit is contained in:
Glenn Condron 2014-06-11 13:45:59 -07:00
parent c14ecd8e7a
commit 611469e3a9
3 changed files with 587 additions and 537 deletions

View File

@ -16,8 +16,6 @@ These are the current minimum requirements, they do not necesarilly represent ou
### Windows ### 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 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+.
* .NET 4.5.1 for hosting in IIS * .NET 4.5.1 for hosting in IIS
* Powershell 4. KVM is a Powershell script that makes use of types that older verisons of Powershell cannot load
### OSX/Linux ### OSX/Linux
* Mono >= 3.4.1 - Currently this means compiling Mono from source from https://github.com/mono/mono * Mono >= 3.4.1 - Currently this means compiling Mono from source from https://github.com/mono/mono
@ -28,11 +26,17 @@ These are the current minimum requirements, they do not necesarilly represent ou
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 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 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'))"
```
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 * Clone the repository
* On the command line execute * On the command line execute
* ```kvmsetup.cmd``` on Windows or * ```kvm setup``` on Windows or
* ```sh kvmsetup.sh && source ~/.kre/kvm/kvm.sh``` on OSX/Linux * ```sh kvmsetup.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.
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. * 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 * Navigate to samples\ConsoleApp
* Run ```kpm restore```. This downloads the System.Console package so the app can do Console.WriteLine * Run ```kpm restore```. This downloads the System.Console package so the app can do Console.WriteLine

94
kvm.ps1
View File

@ -4,6 +4,7 @@ param(
[switch] $verbosity = $false, [switch] $verbosity = $false,
[alias("g")][switch] $global = $false, [alias("g")][switch] $global = $false,
[alias("p")][switch] $persistent = $false, [alias("p")][switch] $persistent = $false,
[alias("f")][switch] $force = $false,
[switch] $x86 = $false, [switch] $x86 = $false,
[switch] $x64 = $false, [switch] $x64 = $false,
[switch] $svr50 = $false, [switch] $svr50 = $false,
@ -21,20 +22,22 @@ $scriptPath = $myInvocation.MyCommand.Definition
function Kvm-Help { function Kvm-Help {
@" @"
K Runtime Environment Version Manager - Build 482 K Runtime Environment Version Manager - Build 509
USAGE: kvm <command> [options] USAGE: kvm <command> [options]
kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global]
install latest KRE from feed install latest KRE from feed
set 'default' alias to installed version set 'default' alias to installed version
add KRE bin to user PATH environment variable persistently add KRE bin to user PATH environment variable
-g|-global install to machine-wide location -g|-global install to machine-wide location
-f|-force upgrade even if latest is already installed
kvm install <semver>|<alias>|<nupkg> [-x86][-x64] [-svr50][-svrc50] [-g|-global] kvm install <semver>|<alias>|<nupkg> [-x86][-x64] [-svr50][-svrc50] [-g|-global]
install requested KRE from feed install requested KRE from feed
add KRE bin to path of current command line add KRE bin to path of current command line
-g|-global install to machine-wide location -g|-global install to machine-wide location
-f|-force install even if specified version is already installed
kvm use <semver>|<alias>|none [-x86][-x64] [-svr50][-svrc50] [-p|-persistent] [-g|-global] kvm use <semver>|<alias>|none [-x86][-x64] [-svr50][-svrc50] [-p|-persistent] [-g|-global]
<semver>|<alias> add KRE bin to path of current command line <semver>|<alias> add KRE bin to path of current command line
@ -146,27 +149,45 @@ function Kvm-Install-Latest {
function Do-Kvm-Download { function Do-Kvm-Download {
param( param(
[string] $kreFullName, [string] $kreFullName,
[string] $kreFolder [string] $packagesFolder
) )
$parts = $kreFullName.Split(".", 2) $parts = $kreFullName.Split(".", 2)
$url = "https://www.myget.org/F/aspnetvnext/api/v2/package/" + $parts[0] + "/" + $parts[1] $url = "https://www.myget.org/F/aspnetvnext/api/v2/package/" + $parts[0] + "/" + $parts[1]
$kreFile = "$kreFolder\$kreFullName.nupkg" $kreFolder = Join-Path $packagesFolder $kreFullName
$kreFile = Join-Path $kreFolder "$kreFullName.nupkg"
If (Test-Path $kreFolder) { If (Test-Path $kreFolder) {
Write-Host "$kreFullName already installed." if($force)
return; {
rm $kreFolder -Recurse -Force
} else {
Write-Host "$kreFullName already installed."
return;
}
} }
Write-Host "Downloading" $kreFullName "from https://www.myget.org/F/aspnetvnext/api/v2/" Write-Host "Downloading" $kreFullName "from https://www.myget.org/F/aspnetvnext/api/v2/"
md $kreFolder -Force | Out-Null #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 = New-Object System.Net.WebClient
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c") $wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
$wc.DownloadFile($url, $kreFile) $wc.DownloadFile($url, $tempKreFile)
Do-Kvm-Unpack $kreFile $kreFolder Do-Kvm-Unpack $tempKreFile $kreTempDownload
md $kreFolder -Force | Out-Null
Write-Host "Installing to $kreFolder"
mv "$kreTempDownload\*" $kreFolder
} }
function Do-Kvm-Unpack { function Do-Kvm-Unpack {
@ -174,10 +195,21 @@ param(
[string] $kreFile, [string] $kreFile,
[string] $kreFolder [string] $kreFolder
) )
Write-Host "Installing to" $kreFolder Write-Host "Unpacking to" $kreFolder
try {
[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null #Shell will not recognize nupkg as a zip and throw, so rename it to zip
[System.IO.Compression.ZipFile]::ExtractToDirectory($kreFile, $kreFolder) $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")) { If (Test-Path ($kreFolder + "\[Content_Types].xml")) {
Remove-Item ($kreFolder + "\[Content_Types].xml") Remove-Item ($kreFolder + "\[Content_Types].xml")
@ -202,8 +234,8 @@ param(
} }
$kreFullName = Requested-VersionOrAlias $versionOrAlias $kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreFolder = "$globalKrePackages\$kreFullName"
Do-Kvm-Download $kreFullName $kreFolder Do-Kvm-Download $kreFullName $globalKrePackages
Kvm-Use $versionOrAlias Kvm-Use $versionOrAlias
} }
@ -215,14 +247,30 @@ param(
{ {
$kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias) $kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
$kreFolder = "$userKrePackages\$kreFullName" $kreFolder = "$userKrePackages\$kreFullName"
$kreFile = "$kreFolder\$kreFullName.nupkg" $folderExists = Test-Path $kreFolder
if (Test-Path($kreFolder)) { if($folderExists -and $force) {
Write-Host "Target folder '$kreFolder' already exists" del $kreFolder -Recurse -Force
$folderExists = $false;
}
if($folderExists) {
Write-Host "Target folder '$kreFolder' already exists"
} else { } else {
md $kreFolder -Force | Out-Null $tempUnpackFolder = Join-Path $userKrePackages "temp"
copy $versionOrAlias $kreFile $tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg"
Do-Kvm-Unpack $kreFile $kreFolder
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
} }
$kreBin = "$kreFolder\bin" $kreBin = "$kreFolder\bin"
@ -233,9 +281,7 @@ param(
{ {
$kreFullName = Requested-VersionOrAlias $versionOrAlias $kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreFolder = "$userKrePackages\$kreFullName" Do-Kvm-Download $kreFullName $userKrePackages
Do-Kvm-Download $kreFullName $kreFolder
Kvm-Use $versionOrAlias Kvm-Use $versionOrAlias
} }
} }

View File

@ -3,7 +3,7 @@ $kvmPs1Path = Join-Path $tempPath "kvm.ps1"
$kvmCmdPath = Join-Path $tempPath "kvm.cmd" $kvmCmdPath = Join-Path $tempPath "kvm.cmd"
Write-Host "Using temporary directory: $tempPath" Write-Host "Using temporary directory: $tempPath"
if (!(Test-Path $tempPath)) { md $tempPath } if (!(Test-Path $tempPath)) { md $tempPath | Out-Null }
$webClient = New-Object System.Net.WebClient $webClient = New-Object System.Net.WebClient