|
| 1 | +:: This script will: |
| 2 | +:: - use Microsoft's PowerShell script (https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script) to install the latest version of all required .NET SDKs. |
| 3 | +:: - install required third-party tools for running these scripts |
| 4 | +:: - add files to the current user's PATH environment variable |
| 5 | + |
| 6 | +:: Requirements: |
| 7 | +:: - PowerShell is enabled on the machine |
| 8 | +:: - Do not install dotnet via any other method (including via installing Visual Studio/Rider). This might otherwise cause two conflicting versions of 'dotnet' to exist in your PATH |
| 9 | + |
| 10 | +@ECHO OFF |
| 11 | + |
| 12 | +:: .NET Versions we want to install and destination |
| 13 | +SET NetVersions=Current 6.0 5.0 3.1 |
| 14 | +SET InstallPath=C:\dotnet |
| 15 | + |
| 16 | +:: Dependencies for these scripts |
| 17 | +SET DepFiles=SnInstallPfx.exe nuget.exe 7z.exe |
| 18 | +SET FileHost=https://files.nateharr.is/netdeps/ |
| 19 | + |
| 20 | +:: Install each .NET version |
| 21 | +@ECHO Installing .NET SDKs ... |
| 22 | +SETLOCAL |
| 23 | + for %%x IN (%NetVersions%) DO ( |
| 24 | + @ECHO Installing .NET %%x ... |
| 25 | + powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -InstallDir %InstallPath% -Channel %%x -Verbose" |
| 26 | + ) |
| 27 | +ENDLOCAL |
| 28 | + |
| 29 | +:: Download dependencies to the same directory as 'dotnet' |
| 30 | +@ECHO Downloading third-party tools ... |
| 31 | +SETLOCAL |
| 32 | + for %%x IN (%DepFiles%) DO ( |
| 33 | + @ECHO Downloading %%x ... |
| 34 | + powershell -NoProfile -ExecutionPolicy unrestricted -Command "Invoke-WebRequest -Uri '%FileHost%%%x' -OutFile '%InstallPath%\%%x'" |
| 35 | + ) |
| 36 | +ENDLOCAL |
| 37 | + |
| 38 | +:: Add dotnet folder to PATH |
| 39 | +powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Environment]::SetEnvironmentVariable('Path', $env:Path + ';%InstallPath%', 'User')" |
| 40 | + |
| 41 | +EXIT /B 0 |
| 42 | + |
| 43 | +:commandFailed |
| 44 | +@ECHO Command failed. |
| 45 | +GOTO :exitWithError |
| 46 | + |
| 47 | +:exitWithError |
| 48 | +@ECHO Exiting... |
| 49 | +EXIT /B 1 |
0 commit comments