"Missing SETLOCAL" when initializing Visual Studio Command Prompt.

Jan 17, 2021
20
0
I'm using:

TCC 27.00.18 x64 Windows 10 [Version 10.0.19042.746]

And just recently installed Microsoft Visual Studio Community 2019, but TCC has some trouble running the command prompt initialization scripts. When running:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"

I get:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.8.3
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************

Cancel batch job C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\dotnet.bat
(Y/N/A) : N
TCC: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\dotnet.bat [282]
Missing SETLOCAL
[vcvarsall.bat] Environment initialized for: 'x86'

Digging into the setup scripts (which are quite extensive):

267 @REM Choose FrameworkDir32 or FrameworkDir64 depending on the preferred bitness.
268 setlocal EnableDelayedExpansion
269 set __DOTNET_FrameworkDir=!FrameworkDir%__DOTNET_PREFERRED_BITNESS%!

When debugging, the "Cancel" seems to come from line 268, and the error message comes from the "endlocal" that should have matched the "setlocal".

Why would I be getting a "Cancel" on a perfectly valid setlocal call?
 
May 20, 2008
11,380
98
Syracuse, NY, USA
I have no problem running that script.

Code:
v:\> ver
TCC 27.00.18 x64
Microsoft Windows 10 Pro for Workstations
10.0.19042.746 (2009, 20H2)

v:\> "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.8.4
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

v:\>
 
Jan 17, 2021
20
0
Can you confirm that it's actually getting to the same line in dotnet.bat?

The initialization system is quite complicated. I can run just:

Code:
 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\dotnet.bat

And get the same problem:

Code:
d:\>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\dotnet.bat"
if "%VSCMD_DEBUG%" GEQ "2" @echo [vsdevcmd\core\%~nx0] initializing...
set __dotnet_error_count=0
if "%VSCMD_TEST%" NEQ "" goto :test
if "%VSCMD_ARG_CLEAN_ENV%" NEQ "" goto :clean_env
if "%VSCMD_ARG_TGT_ARCH%"=="x86" ( set __DOTNET_ADD_32BIT=1 )
if "%VSCMD_ARG_TGT_ARCH%"=="x64" ( set __DOTNET_ADD_64BIT=1 )
if "%VSCMD_ARG_HOST_ARCH%"=="x86" ( set __DOTNET_ADD_32BIT=1 & set __DOTNET_PREFERRED_BITNESS=32 ) else if "%VSCMD_ARG_HOST_ARCH%"=="x64" ( set __DOTNET_ADD_64BIT=1 & set __DOTNET_PREFERRED_BITNESS=64 ) else ( @echo ERROR: Invalid host architecture '%VSCMD_ARG_HOST_ARCH%'. & set /A __dotnet_error_count=__dotnet_error_count+1 )
ERROR: Invalid host architecture ''.
if "%VSCMD_DEBUG%" GEQ "2" ( if "%__DOTNET_ADD_32BIT%"=="1" @echo [DEBUG:core\%~nx0] Adding 32-bit .NET Framework Path & if "%__DOTNET_ADD_64BIT%"=="1" @echo [DEBUG:core\%~nx0] Adding 64-bit .NET Framework Path & @echo [DEBUG:core\%~nx0] Framework Preference: %__DOTNET_PREFERRED_BITNESS%bit )
if "%__DOTNET_ADD_32BIT%"=="1" ( @call :GetFrameworkDir32 & @call :GetFrameworkVer32 & @call :CheckFramework32 )
if "%__DOTNET_ADD_64BIT%"=="1" ( @call :GetFrameworkDir64 & @call :GetFrameworkVer64 & @call :CheckFramework64 )
set Framework40Version=v4.0
call :CheckFramework40Version
if "%Framework40Version%"=="" ( @echo ERROR: Cannot determine the .NET Framework 4.0 version. & exit /B 1 )
exit /B 0
goto :export_env
setlocal EnableDelayedExpansion

Cancel batch job C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\dotnet.bat ? (Y/N/A) : N
set __DOTNET_FrameworkDir=
set __DOTNET_FrameworkVersion=
if "__DOTNET_FrameworkDir"=="" ( @echo ERROR: FrameworkDir%__DOTNET_PREFERRED_BITNESS% cannot be found. & set /A __dotnet_error_count=__dotnet_error_count+1 )
if "__DOTNET_FrameworkVersion"=="" ( @echo ERROR: FrameworkVersion%__DOTNET_PREFERRED_BITNESS% cannot be found. & set /A __dotnet_error_count=__dotnet_error_count+1 )
endlocal
TCC: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\dotnet.bat [282]  Missing SETLOCAL
set "FrameworkDir="
set "FrameworkVersion="
if NOT "%FrameworkDir:~-1%"=="\" ( if "%VSCMD_DEBUG%" GEQ "2" @echo [DEBUG:core\%~nx0] appending '\' to FrameworkDir. & set "FrameworkDir=%FrameworkDir%\" )
if exist "%FrameworkDir%%Framework40Version%" set "PATH=%FrameworkDir%%Framework40Version%;%PATH%"
if exist "%FrameworkDir%%FrameworkVersion%" set "PATH=%FrameworkDir%%FrameworkVersion%;%PATH%"
if exist "%FrameworkDir%%Framework40Version%" set "LIBPATH=%FrameworkDir%%Framework40Version%;%LIBPATH%"
if exist "%FrameworkDir%%FrameworkVersion%" set "LIBPATH=%FrameworkDir%%FrameworkVersion%;%LIBPATH%"
if "%__dotnet_error_count%" NEQ "0" ( set __dotnet_error_count= & exit /B 1 )
 
May 20, 2008
11,380
98
Syracuse, NY, USA
I put a comment just before that line (it's 267 here).

Code:
@REM Choose FrameworkDir32 or FrameworkDir64 depending on the preferred bitness.
echo at line 268
setlocal EnableDelayedExpansion

And ...
Code:
v:\> "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.8.4
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
at line 268
[vcvarsall.bat] Environment initialized for: 'x86'

v:\>
 
Jan 17, 2021
20
0
Okay, so it's probably a configuration thing. I just did a little experiment with a CMD file called setit.cmd:

Code:
setlocal ENABLEEXTENSIONS

Literally, just that. If I open a brand new TCC prompt, I get the "CANCEL". If I run it a second time, it's doesn't complain.

Code:
d:\tmp>setit.cmd
setlocal ENABLEEXTENSIONS

Cancel batch job D:\tmp\setit.cmd ? (Y/N/A) : A

d:\tmp>setit.cmd
setlocal ENABLEEXTENSIONS

d:\tmp>
 
Jan 17, 2021
20
0
Okay, I'm narrowing it down to the LOCAL and GLOBAL lists:

This causes the error:
1610912222851.png

And this doesn't:
1610912254712.png
 
Jan 17, 2021
20
0
Yup. Found it.

Both "Functions" and "Aliases" must have one or the other checked. If neither are checked, SETLOCAL fails.

The same does not seem to be true for "History" and "Directory History".

Thanks for helping me nail this down @vefatica !!

I have a work around (honestly I'm not sure HOW I want the lists set and don't quite understand the meaning yet) and I think this should be a bug in TCC 27.
 
May 20, 2008
11,380
98
Syracuse, NY, USA
These settings are OK (for this problem).

1610914592952.png


But they cause this to happen. I issue FUNCTION or ALIAS and get the SET command!

1610914662431.png

1610914749575.png
 
Aug 23, 2010
636
9
In general, I suggest you don't use TCC for scripts written for CMD.
There's too many caveats to have it working stable enough for consistent results.
 
Similar threads
Thread starter Title Forum Replies Date
Jay Sage Documentation Function @DRIVE Missing in Help Lists Support 0
A Key Commands missing? Support 3
L How to? Shebang, nice idea but am I missing something? Support 4
A How to? TCMD Configuration Dialog: 'Smooth Scrolling' Option missing? Support 1
Z Take Command deletes the next letter when I insert a missing letter ? Support 5
Joe Caverly Missing PSHELL in HELP Support 0
JohnQSmith Weird DIR output (missing lines) Support 1
dcantor Documentation SET /T: missing from heading Support 0
M Is STDVCL40.DLL missing or no longer needed? Support 4
vefatica Missing DLL Support 21
E Fixed SHRALIAS doesn't work / SHRALIAS.EXE is missing in v20.11.35 Support 2
vefatica Fixed Help @FUNCTION, missing paragraph Support 8
vefatica Missing post and security error Support 4
Roedy missing English.dll, failed install Support 2
D MSVCP140.dll is missing Support 5
C WAD Logging missing Support 19
H Fixed ... MSVCR120.dll is missing from your system ... Support 2
vefatica Help pages, icon missing Support 8
J The triple mystery of the missing tray icon Support 9
L Full Screen in Office 2013 theme chars missing Support 8
vefatica Build 55: ipworks9.dll missing Support 8
S How to? How do I distinguish missing source file from download error when using HTTP? Support 6
S Documentation "HELP IDE" - missing reference Support 0
vefatica Missing VirtualizerSDK32.dll Support 8
Dan Glynhampton Documentation v15 help: Missing link Support 0
M Missing PERL command-line arguments Support 1
Dan Glynhampton Documentation Bad Link/Missing Page in v15 help Support 0
S Missing thread Support 9
S dir for ftp connection - missing files sometimes Support 1
R CompleteAllFiles missing in option? Support 1
Joe Caverly Sort-of Missing Switch for START in Help Support 7
M How to? Missing closing quote: What am I doing wrong???? Support 7
dcantor SENDMAIL /= missing field Support 4
S DEL on FTP site : complaint about missing DESCRIPT.ION Support 1
Steve Pitts FOLDERMONITOR missing events?? Support 7
M Missing PDir option... Support 5
rnwolf can't start because ipworks8.dll is missing Support 1
thedave Newly created directories missing from TCMD Support 0
dcantor Missing help for @PIDCOMMAND[pid] Support 6
dcantor @TIMEZONE missing from help Support 4
C Rex: Missing email messages from all forums Support 7
L Vista 64 bits missing commands Support 1
K seems to have no effec tin CMDebug: SETLOCAL EnableDelayedExpansion Support 1
cgunhouse SETLOCAL not working in BDEBUGGER Support 9
Joe Caverly How to? SETLOCAL Level Support 16
Joe Caverly SETLOCAL removes Aliases and Functions Support 3
vefatica SETLOCAL ... ALIAS ... pipes Support 2
rps WAD Setlocal issue Support 4
Charles Dye Read-only environment variables wiped by SETLOCAL / ENDLOCAL Support 5
T Documentation SETARRAY & SETLOCAL/ENDLOCAL Support 8

Similar threads