2015-11-16 11:21:57 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								#  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Copyright (c) .NET Foundation and contributors. All rights reserved.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Licensed under the MIT license. See LICENSE file in the project root for full license information.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								#  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								param (  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   [ string ] $Channel = " dev " , 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-23 18:04:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								   [ string ] $version = " Latest " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   [ string ] $Architecture = " x64 " 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								)  
						 
					
						
							
								
									
										
										
										
											2016-01-20 18:49:47 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								$ErrorActionPreference = " Stop "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$ProgressPreference = " SilentlyContinue "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$fileVersion  =  $Version  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( $fileVersion  -eq  " Latest " )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $fileVersion  =  " latest " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								$Feed = " https://dotnetcli.blob.core.windows.net/dotnet "  
						 
					
						
							
								
									
										
										
										
											2016-02-23 18:04:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$DotNetFileName = " dotnet-win- $Architecture . $fileVersion .zip "  
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								$DotNetUrl = " $Feed / $Channel /Binaries/ $Version "  
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function   say($str )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Write-Host  " dotnet_install:  $str " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$InstallDir  =  $env:DOTNET_INSTALL_DIR  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( ! $InstallDir )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $InstallDir  =  " $env:LocalAppData \Microsoft\dotnet " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								say  " Preparing to install .NET Tools to  $InstallDir "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Check if we need to bother  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$LocalFile  =  " $InstallDir \cli\.version "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( Test-Path  $LocalFile )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $LocalData  =  @ ( cat  $LocalFile ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $LocalHash  =  $LocalData [ 0 ] . Trim ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $LocalVersion  =  $LocalData [ 1 ] . Trim ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( $LocalVersion  -and  $LocalHash ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( $Version  -eq  " Latest " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-23 18:04:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $RemoteResponse  =  Invoke-WebRequest  -UseBasicParsing  " $Feed / $Channel /dnvm/latest.win. $Architecture .version " 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $RemoteData  =  @ ( [ Text.Encoding ] :: UTF8 . GetString ( $RemoteResponse . Content ) . Split ( [ char[] ] @ ( ) ,  [ StringSplitOptions ] :: RemoveEmptyEntries ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $RemoteHash  =  $RemoteData [ 0 ] . Trim ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $RemoteVersion  =  $RemoteData [ 1 ] . Trim ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if  ( ! $RemoteVersion  -or  ! $RemoteHash )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                throw  " Invalid response from feed " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            say  " Latest version:  $RemoteVersion " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            say  " Local Version:  $LocalVersion " 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            if ( $LocalHash  -eq  $RemoteHash ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                say  " You already have the latest version " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                exit  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        elseif  ( $LocalVersion  -eq  $Version ) 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
									
										
										
										
											2016-02-11 10:47:49 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            say  " $Version  is already installed. " 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            exit  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Set up the install location  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( ! ( Test-Path  $InstallDir ) )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    mkdir  $InstallDir  |  Out-Null 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# De-powershell the path before passing to .NET APIs  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$InstallDir  =  Convert-Path  $InstallDir  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								say  " Downloading  $DotNetFileName  from  $DotNetUrl "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								$resp  =  Invoke-WebRequest  -UseBasicParsing  " $DotNetUrl / $DotNetFileName "  -OutFile  " $InstallDir \ $DotNetFileName "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								say  " Extracting zip "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Create the destination  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( Test-Path  " $InstallDir \cli_new " )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    del  -rec  -for  " $InstallDir \cli_new " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								mkdir  " $InstallDir \cli_new "  |  Out-Null  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Add-Type  -Assembly  System . IO . Compression . FileSystem  |  Out-Null  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ System.IO.Compression.ZipFile ] :: ExtractToDirectory ( " $InstallDir \ $DotNetFileName " ,  " $InstallDir \cli_new " )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Replace the old installation (if any)  
						 
					
						
							
								
									
										
										
										
											2015-11-13 13:32:21 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								if  ( Test-Path  " $InstallDir \cli " )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    del  -rec  -for  " $InstallDir \cli " 
							 
						 
					
						
							
								
									
										
										
										
											2015-11-10 17:30:01 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								mv  " $InstallDir \cli_new "  " $InstallDir \cli "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# Clean the zip  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  ( Test-Path  " $InstallDir \ $DotNetFileName " )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    del  -for  " $InstallDir \ $DotNetFileName " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-11-16 13:49:29 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								say  " The .NET Tools have been installed to  $InstallDir \cli! "  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# New layout  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								say  " Add ' $InstallDir \cli\bin' to your PATH to use dotnet "