Repository navigation
Expand file tree
/
Copy pathdeploy-exp.cmd
More file actions
126 lines (112 loc) · 5.11 KB
/
Copy pathdeploy-exp.cmd
File metadata and controls
126 lines (112 loc) · 5.11 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@echo off
REM =====================================================================
REM Deploy the extension into the Visual Studio experimental hive (Exp).
REM
REM deploy-exp.cmd Build Debug and deploy to the Exp hive.
REM deploy-exp.cmd -release Build Release instead of Debug.
REM deploy-exp.cmd -run The above, then start devenv /rootsuffix Exp
REM with this solution loaded.
REM deploy-exp.cmd -run -open <path>
REM Start Exp with another solution or folder
REM instead (e.g. a demo app, so F5 debugs it).
REM
REM F5 and Ctrl+F5 from Visual Studio already deploy on their own, for
REM Debug and Release alike (the csproj sets DeployExtension for builds
REM inside VS). This script is the command-line equivalent, and the way
REM to recover when the Exp hive loses the extension: it retries after
REM rebuilding the hive's extension cache, which is what
REM "VSSDK1031 ... could not be found" on a first deploy needs. Before
REM either attempt it ends idle MSBuild nodes left by VS builds, which keep
REM the hive's registry locked and cause the same VSSDK1031 (see :releasehive).
REM
REM Either way the build removes any older version folder left in the
REM hive (RemoveStaleExpDeployments in the csproj) — two folders sharing
REM one VSIX identity is what makes Exp silently keep running the old
REM build after a version bump.
REM =====================================================================
setlocal EnableDelayedExpansion
REM Before parsing: shift also moves %0, so %~dp0 would point elsewhere.
set "ROOT=%~dp0"
REM --- Arguments (order-independent) -----------------------------------
set "CONFIG=Debug"
set "RUNAFTER="
set "OPENPATH="
:parseargs
if "%~1"=="" goto parsed
if /i "%~1"=="-release" set "CONFIG=Release"
if /i "%~1"=="-debug" set "CONFIG=Debug"
if /i "%~1"=="-run" set "RUNAFTER=1"
if /i "%~1"=="-open" (
set "OPENPATH=%~2"
shift
)
shift
goto parseargs
:parsed
REM --- Tool locations, VS 2026 first then VS 2022, any edition -----------
set "VSROOT="
for %%V in (18 2022) do for %%E in (Enterprise Professional Community) do (
if not defined VSROOT if exist "C:\Program Files\Microsoft Visual Studio\%%V\%%E\MSBuild\Current\Bin\MSBuild.exe" (
set "VSROOT=C:\Program Files\Microsoft Visual Studio\%%V\%%E"
)
)
set "MSBUILD=%VSROOT%\MSBuild\Current\Bin\MSBuild.exe"
set "DEVENV=%VSROOT%\Common7\IDE\devenv.exe"
set "PROJ=%ROOT%ClaudeCodeExtension.csproj"
set "SLN=%ROOT%ClaudeCodeExtension.sln"
if defined OPENPATH set "SLN=%OPENPATH%"
if defined RUNAFTER if not exist "%SLN%" (
echo [ERROR] Not found: %SLN%
exit /b 1
)
REM Full path: launched from Git Bash, a bare "find" resolves to GNU find.
set "FINDEXE=%SystemRoot%\System32\find.exe"
if not exist "%MSBUILD%" (
echo [ERROR] MSBuild.exe not found.
exit /b 1
)
if not exist "%DEVENV%" (
echo [ERROR] devenv.exe not found.
exit /b 1
)
REM Deploying over a running experimental instance leaves it on the old
REM binaries and can fail the copy outright.
tasklist /fi "imagename eq devenv.exe" | "%FINDEXE%" /i "devenv.exe" >nul
if not errorlevel 1 (
echo [WARN] Visual Studio is running. Close any /rootsuffix Exp instance
echo before deploying, or it will keep the previous build loaded.
)
call :releasehive
echo Building %CONFIG% and deploying to the Exp hive...
"%MSBUILD%" "%PROJ%" -t:Build -p:Configuration=%CONFIG% -p:DeployExtension=true -p:VSSDKTargetPlatformRegRootSuffix=Exp -nodeReuse:false -v:minimal -nologo
if errorlevel 1 (
echo.
echo [INFO] Deploy failed. Rebuilding the Exp extension cache and retrying...
call :releasehive
"%DEVENV%" /rootsuffix Exp /updateconfiguration
"%MSBUILD%" "%PROJ%" -t:Build -p:Configuration=%CONFIG% -p:DeployExtension=true -p:VSSDKTargetPlatformRegRootSuffix=Exp -nodeReuse:false -v:minimal -nologo
if errorlevel 1 (
echo.
echo [ERROR] Deploy to the Exp hive failed.
exit /b 1
)
)
echo.
echo [OK] Deployed to %LocalAppData%\Microsoft\VisualStudio\^<version^>Exp\Extensions\Daniel Carvalho Liedke
if defined RUNAFTER (
echo Starting the experimental instance...
start "" "%DEVENV%" /rootsuffix Exp "%SLN%"
)
endlocal
exit /b 0
REM --- :releasehive ------------------------------------------------------
REM The deploy tasks (FindInstalledExtension, EnableExtension) run in a
REM 32-bit MSBuild task host, and builds inside VS leave that host alive
REM (/nodereuse:True) with the Exp hive's privateregistry.bin still open.
REM While it lives, every other process sees an empty hive: the deploy
REM fails with VSSDK1031 and /updateconfiguration silently merges nothing.
REM Ending the idle reusable nodes releases the hive; VS starts fresh ones
REM on its next build.
:releasehive
powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \"name='MSBuild.exe'\" | Where-Object { $_.CommandLine -match '/nodemode:' } | ForEach-Object { Write-Host ('[INFO] Ending idle MSBuild node ' + $_.ProcessId + ' that locks the Exp hive.'); Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }"
exit /b 0