-
Notifications
You must be signed in to change notification settings - Fork 850
Expand file tree
/
Copy pathDevCmd.cmd
More file actions
105 lines (86 loc) · 3.44 KB
/
Copy pathDevCmd.cmd
File metadata and controls
105 lines (86 loc) · 3.44 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
@echo off
rem Scripts cannot set enviroment variables because of an older handler in the agent that is not compatible with some pipeline containers
rem Hence to set enviroment variables, use SetEnviromentVariable
goto :begin
:PrintVsWhere
@echo on
%vswhere% -products Microsoft.VisualStudio.Product.BuildTools -property InstallationPath %PrereleaseArg%
%vswhere% -requires Microsoft.Component.MSBuild -property InstallationPath %PrereleaseArg%
@echo off
exit /b 0
rem This function is used to set enviroment variables in Azure Pipelines
:SetEnviromentVariable
set _varName=%~1
set _varValue=%~2
set %_varName%=%_varValue%
if not "%Pipeline%"=="true" (
@REM I don't know why but if I put the echo line in here, it modifies the value, just batch things
set _varName=
set _varValue=
exit /b 0
)
echo ##vso[task.setVariable variable=%_varName%]%_varValue%
set _varName=
set _varValue=
exit /b 0
:begin
pushd %~dp0
PATH %PATH%;%~dp0\tools
set PrereleaseArg=
setlocal enableextensions enabledelayedexpansion
set _ARGS=
rem We are targeting VS 2019 (version 16.x) or later
set VsVersion=16.0
if exist %temp%\WinUI.PreserveContext.marker del %temp%\WinUI.PreserveContext.marker
:ParseArgs
if "%1" EQU "" (
goto :DoneParsing
) else if /i "%1" EQU "/PreserveContext" (
echo. > %temp%\WinUI.PreserveContext.marker
) else if /i "%1" EQU "/Prerelease" (
set PrereleaseArg=-prerelease
) else (
set _ARGS=%_ARGS% %1=%2
shift
)
shift
goto ParseArgs
:DoneParsing
set vswhere="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist %vswhere% (echo VSWhere.exe not found. Install MSBuild first from OneTimeSetup.cmd && exit /b 1)
rem Try MSBuild first
set MSBuildInstallpath=
for /f "tokens=*" %%a in ('%vswhere% -products Microsoft.VisualStudio.Product.BuildTools -property InstallationPath %PrereleaseArg% -latest -version %VsVersion%') do set MSBuildInstallPath=%%a
if "%MSBuildInstallPath%" EQU "" (
rem We didn't find MSBuild, try a full VSexit
for /f "tokens=*" %%a in ('%vswhere% -requires Microsoft.Component.MSBuild -property InstallationPath %PrereleaseArg% -latest -version %VsVersion%') do set MSBuildInstallPath=%%a
)
if "%MSBuildInstallPath%" EQU "" (
echo Could not find an MSBuild install, exiting
if defined AGENT_NAME (
call :PrintVsWhere
)
exit /b 2
)
rem In the pipeline, vswhere cannot locate VS build tools installed as part of the pipeline run without a restart. If the .buildtools directory exists,
rem implying the pipeline installed VS build tools, use them instead.
if exist %~dp0.buildtools (
echo Using MSBuild from .buildtools directory...
set MSBuildInstallPath=%~dp0.buildtools
) else (
echo .buildtools directory not found, using msbuild from vswhere...
)
endlocal & (
echo "Initializing VS command prompt from %MSBuildInstallPath%\Common7\Tools\VsDevCmd.bat ..."
call "%MSBuildInstallPath%\Common7\Tools\VsDevCmd.bat" /no_logo %_ARGS%
)
rem These variables are set in VsDevCmd.bat but we need to set them again with SetEnviromentVariable to work in pipeline containers
call :SetEnviromentVariable VCToolsInstallDir "%VCToolsInstallDir%"
call :SetEnviromentVariable VCToolsRedistDir "%VCToolsRedistDir%"
call :SetEnviromentVariable ExtensionSdkDir "%ExtensionSdkDir%"
if not exist %temp%\WinUI.PreserveContext.marker (
echo Starting cmd /k
cmd /k "cd /d %RepoRoot%"
)
if exist %temp%\WinUI.PreserveContext.marker (del %temp%\WinUI.PreserveContext.marker)
exit /b 0