This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathdotnet-install.cmd
85 lines (72 loc) · 2.72 KB
/
dotnet-install.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@if not defined _echo echo off
:install_dotnet_cli
setlocal
set "DOTNET_MULTILEVEL_LOOKUP=0"
set "UseSharedCompilation=false"
set /p DotNet_Version=<"%~dp0DotNetCLIVersion.txt"
if not defined DotNet_Version (
call :print_error_message Unknown DotNet CLI Version.
exit /b 1
)
set "DotNet_Path=%~dp0tools\dotnet\%DotNet_Version%"
set "DotNet=%DotNet_Path%\dotnet.exe"
set "DotNet_Installer_Url=https://raw.githubusercontent.com/dotnet/cli/v%DotNet_Version%/scripts/obtain/dotnet-install.ps1"
REM dotnet.exe might exist, but it might not be the right version.
REM Here we verify that if it is not the right version, then we install it
if exist "%DotNet%" (
(call "%DotNet%" --version|findstr.exe /i /c:"%DotNet_Version%" 1>nul 2>&1) && goto :install_dotnet_cli_exit
call :print_error_message Current version of "%DotNet%" does not match expected version "%DotNet_Version%"
call :remove_directory "%DotNet_Path%" || exit /b 1
)
if not exist "%DotNet_Path%" mkdir "%DotNet_Path%"
if not exist "%DotNet_Path%" (
call :print_error_message Unable to create the "%DotNet_Path%" folder.
exit /b 1
)
call :print_header_message Downloading dotnet-install.ps1
powershell -NoProfile -ExecutionPolicy unrestricted -Command "Invoke-WebRequest -Uri '%DotNet_Installer_Url%' -OutFile '%DotNet_Path%\dotnet-install.ps1'"
if not exist "%DotNet_Path%\dotnet-install.ps1" (
call :print_error_message Failed to download "%DotNet_Path%\dotnet-install.ps1"
exit /b 1
)
call :print_header_message Executing dotnet installer script "%DotNet_Path%\dotnet-install.ps1"
call :print_header_message Installing .NET Core SDK %DotNet_Version%
powershell -NoProfile -ExecutionPolicy unrestricted -Command "&'%DotNet_Path%\dotnet-install.ps1' -InstallDir '%DotNet_Path%' -Version '%DotNet_Version%'" || (
call :print_error_message Failed to install .NET Core SDK %DotNet_Version%
exit /b 1
)
if not exist "%DotNet%" (
call :print_error_message Failed to install dotnet cli.
exit /b 1
)
:install_dotnet_cli_exit
ECHO/
call "%DotNet%" --info
ECHO/
endlocal& (
set "PATH=%DotNet_Path%;%PATH%"
exit /b 0
)
:print_error_message
echo/
echo/ [ERROR] %*
echo/
exit /b %errorlevel%
:print_header_message
echo/
echo/------------------------------------------------------------------------------
echo/ %*
echo/------------------------------------------------------------------------------
echo/
exit /b %errorlevel%
:remove_directory
if "%~1" == "" (
call :print_error_message Directory name was not specified.
exit /b 1
)
if exist "%~1" rmdir /s /q "%~1"
if exist "%~1" (
call :print_error_message Failed to remove directory "%~1".
exit /b 1
)
exit /b 0