"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,158
93
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,158
93
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,158
93
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
623
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.