1 @if not defined _echo @echo off
4 set INIT_TOOLS_LOG=%~dp0init-tools.log
5 if [%PACKAGES_DIR%]==[] set PACKAGES_DIR=%~dp0packages\
6 if [%TOOLRUNTIME_DIR%]==[] set TOOLRUNTIME_DIR=%~dp0Tools
7 set DOTNET_PATH=%TOOLRUNTIME_DIR%\dotnetcli\
8 if [%DOTNET_CMD%]==[] set DOTNET_CMD=%DOTNET_PATH%dotnet.exe
9 if [%BUILDTOOLS_SOURCE%]==[] set BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json
10 set /P BUILDTOOLS_VERSION=< "%~dp0BuildToolsVersion.txt"
11 set BUILD_TOOLS_PATH=%PACKAGES_DIR%Microsoft.DotNet.BuildTools\%BUILDTOOLS_VERSION%\lib\
12 set INIT_TOOLS_RESTORE_PROJECT=%~dp0init-tools.msbuild
13 set BUILD_TOOLS_SEMAPHORE_DIR=%TOOLRUNTIME_DIR%\%BUILDTOOLS_VERSION%
14 set BUILD_TOOLS_SEMAPHORE=%BUILD_TOOLS_SEMAPHORE_DIR%\init-tools.completed
16 :: if force option is specified then clean the tool runtime and build tools package directory to force it to get recreated
18 if exist "%TOOLRUNTIME_DIR%" rmdir /S /Q "%TOOLRUNTIME_DIR%"
19 if exist "%PACKAGES_DIR%Microsoft.DotNet.BuildTools" rmdir /S /Q "%PACKAGES_DIR%Microsoft.DotNet.BuildTools"
22 :: If semaphore exists do nothing
23 if exist "%BUILD_TOOLS_SEMAPHORE%" (
24 echo %__MsgPrefix%Tools are already initialized.
28 if exist "%TOOLRUNTIME_DIR%" rmdir /S /Q "%TOOLRUNTIME_DIR%"
30 if exist "%DotNetBuildToolsDir%" (
31 echo Using tools from '%DotNetBuildToolsDir%'.
32 mklink /j "%TOOLRUNTIME_DIR%" "%DotNetBuildToolsDir%"
34 if not exist "%DOTNET_CMD%" (
35 echo ERROR: Ensure that '%DotNetBuildToolsDir%' contains the .NET Core SDK at '%DOTNET_PATH%'
39 echo Done initializing tools.
40 echo Using tools from '%DotNetBuildToolsDir%'. > "%BUILD_TOOLS_SEMAPHORE%"
44 echo Running %0 > "%INIT_TOOLS_LOG%"
46 set /p DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"
47 if exist "%DOTNET_CMD%" goto :afterdotnetrestore
49 echo %__MsgPrefix%Installing dotnet cli...
50 if NOT exist "%DOTNET_PATH%" mkdir "%DOTNET_PATH%"
51 set DOTNET_ZIP_NAME=dotnet-sdk-%DOTNET_VERSION%-win-x64.zip
52 set DOTNET_REMOTE_PATH=https://dotnetcli.azureedge.net/dotnet/Sdk/%DOTNET_VERSION%/%DOTNET_ZIP_NAME%
53 set DOTNET_LOCAL_PATH=%DOTNET_PATH%%DOTNET_ZIP_NAME%
54 echo %__MsgPrefix%Installing '%DOTNET_REMOTE_PATH%' to '%DOTNET_LOCAL_PATH%' >> "%INIT_TOOLS_LOG%"
55 powershell -NoProfile -ExecutionPolicy unrestricted -Command "$retryCount = 0; $success = $false; do { try { (New-Object Net.WebClient).DownloadFile('%DOTNET_REMOTE_PATH%', '%DOTNET_LOCAL_PATH%'); $success = $true; } catch { if ($retryCount -ge 6) { throw; } else { $retryCount++; Start-Sleep -Seconds (5 * $retryCount); } } } while ($success -eq $false); Add-Type -Assembly 'System.IO.Compression.FileSystem' -ErrorVariable AddTypeErrors; if ($AddTypeErrors.Count -eq 0) { [System.IO.Compression.ZipFile]::ExtractToDirectory('%DOTNET_LOCAL_PATH%', '%DOTNET_PATH%') } else { (New-Object -com shell.application).namespace('%DOTNET_PATH%').CopyHere((new-object -com shell.application).namespace('%DOTNET_LOCAL_PATH%').Items(),16) }" >> "%INIT_TOOLS_LOG%"
56 if NOT exist "%DOTNET_LOCAL_PATH%" (
57 echo %__MsgPrefix%ERROR: Could not install dotnet cli correctly. 1>&2
63 if exist "%BUILD_TOOLS_PATH%" goto :afterbuildtoolsrestore
64 echo %__MsgPrefix%Restoring BuildTools version %BUILDTOOLS_VERSION%...
65 echo %__MsgPrefix%Running: "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% /p:ToolsDir=%TOOLRUNTIME_DIR% >> "%INIT_TOOLS_LOG%"
66 call "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% /p:ToolsDir=%TOOLRUNTIME_DIR% >> "%INIT_TOOLS_LOG%"
67 if NOT exist "%BUILD_TOOLS_PATH%init-tools.cmd" (
68 %__MsgPrefix%echo ERROR: Could not restore build tools correctly. 1>&2
72 :afterbuildtoolsrestore
74 :: Ask init-tools to also restore ILAsm
75 set /p ILASMCOMPILER_VERSION=< "%~dp0ILAsmVersion.txt"
77 echo %__MsgPrefix%Initializing BuildTools...
78 echo %__MsgPrefix%Running: "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
79 call "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
80 set INIT_TOOLS_ERRORLEVEL=%ERRORLEVEL%
81 if not [%INIT_TOOLS_ERRORLEVEL%]==[0] (
82 echo ERROR: An error occured when trying to initialize the tools. 1>&2
86 :: Create semaphore file
87 echo %__MsgPrefix%Done initializing tools.
88 if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" (
89 mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
91 echo %__MsgPrefix%Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%"
95 echo %__MsgPrefix%Please check the detailed log that follows. 1>&2
96 type "%INIT_TOOLS_LOG%" 1>&2