title: How to solve: "nvcc fatal : Could not set up the environment for Microsoft Visual Studio using vcvars64.bat"
body: <p>I'm trying to build a CMake project using Visual Studio (open folder mode).
  Nvcc is required to build the project.</p>
  
  <p>I get the following error:</p>
  
  <pre><code>  The CUDA compiler
  
      "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/bin/nvcc.exe"
  
    is not able to compile a simple test program.
  
    It fails with the following output:
  
      Change Dir: [PROJECT_PATH]/build/Test_Release/CMakeFiles/CMakeTmp
  
      Run Build Command:"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" "cmTC_d4aa6"
      [1/3] Building CUDA object CMakeFiles\cmTC_d4aa6.dir\main.cu.obj
      FAILED: CMakeFiles/cmTC_d4aa6.dir/main.cu.obj 
      cmd.exe /C "C:\PROGRA~1\NVIDIA~2\CUDA\v10.1\bin\nvcc.exe     -x cu -c main.cu -o CMakeFiles\cmTC_d4aa6.dir\main.cu.obj &amp;&amp; C:\PROGRA~1\NVIDIA~2\CUDA\v10.1\bin\nvcc.exe     -x cu -M main.cu -MT CMakeFiles\cmTC_d4aa6.dir\main.cu.obj -o CMakeFiles\cmTC_d4aa6.dir\main.cu.obj.d"
      nvcc fatal   : Could not set up the environment for Microsoft Visual Studio using 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat'
      ninja: build stopped: subcommand failed.
  
  
  
    CMake will not be able to correctly generate this project.        C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.13/Modules/CMakeTestCUDACompiler.cmake   46  
  </code></pre>
  
  <p>I tried different combinations of Nvidia CUDA Toolkit (10.0, 10.1) and Microsoft Visual Studio (2017 - MSVC 14.16, 2019 - MSVC 14.20). None of these gets rid of the error.</p>
  
  <p>I built successfully the project on other machines, with the same versions of visual studio and nvcc.</p>