Skip to content

[bug] conanvcvars.bat should activate only once, since it can't be deactivated. #19423

@jeroendv

Description

@jeroendv

Describe the bug

Current behavior

The VCVars generator generates two scripts one to activate and another to deactivate the conan build environment.

The deactivate does however not deactivate at all, it only contains a warning stating that fact.

echo [deactivate_conanvcvars.bat]: *** vcvars env cannot be deactivated ***

so repeated calls to setup and teardown the conan build environment causes the PATH environment variable to accumulate with copies of itself until the max length is reached and an error it thrown.

environment

$ conan version
version: 2.24.0
conan_path: D:\dev\.conda\envs\conan2\Scripts\conan
python
  version: 3.14.2
  sys_version: 3.14.2 | packaged by conda-forge | (main, Dec  6 2025, 11:17:27) [MSC v.1944 64 bit (AMD64)]
  sys_executable: D:\dev\.conda\envs\conan2\python.exe
  is_frozen: False
  architecture: AMD64
system
  version: 10.0.26100
  platform: Windows-11-10.0.26100-SP0
  system: Windows
  release: 11
  cpu: Intel64 Family 6 Model 141 Stepping 1, GenuineIntel

How to reproduce it

create a conanfile

from conan import ConanFile

class BasicConanfile(ConanFile):
    name = "mypkg"
    version = "0.1"

    settings = "os", "compiler", "arch", "build_type"


    generators = "VCVars"

then repeatedly activate and deactivate the build environment until the error is raises

> conanbuild.bat
[vcvarsall.bat] Environment initialized for: 'x64'
Activating environ

> deactivate_conanbuild.bat
Restoring environment 
[deactivate_conanvcvars.bat]: *** vcvars env cannot be deactivated ***

> conanbuild.bat
...
> deactivate_conanbuild.bat
...
> conanbuild.bat
conanvcvars.bat: Activating environment Visual Studio 16 - amd64 - winsdk_version=None - vcvars_ver=14.2
The input line is too long.
The syntax of the command is incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions