title: How to force CLion using a custom MSVC version?
body: <h1>The problem</h1>
  <p>I use CLion 2022.2, Visual Studio 2022, and CMake 3.23. I want to use the toolset of version 14.31.17.1, which is older than the newest one.</p>
  <h1>Configure</h1>
  <p>I configure the CMake project with a <code>CMakeLists.txt</code> file</p>
  <pre><code>project(test_project)
  add_executable(test_project main.cpp)
  </code></pre>
  <p>In CLion, I specify generator Visual Studio 2022 and a toolset 14.31.17.1. The command executed is</p>
  <pre><code>&quot;C:\Program Files\CMake\bin\cmake.exe&quot; -G &quot;Visual Studio 17 2022&quot; -T version=14.31.17.1 -S F:\test_project -B F:\test_project\build
  </code></pre>
  <p>Nevertheless, logs say</p>
  <pre><code>-- The C compiler identification is MSVC 19.33.31629.0
  -- The CXX compiler identification is MSVC 19.33.31629.0
  </code></pre>
  <p>When I clear the cache directory and execute the same command in CLion Terminal (copy and paste it with the <code>.</code> or <code>&amp;</code> prefix), I get what I want</p>
  <pre><code>-- The C compiler identification is MSVC 19.31.31107.0
  -- The CXX compiler identification is MSVC 19.31.31107.0
  </code></pre>
  <p>Note: toolset 14.31.31103 contains MSVC 19.31.31107.0 while toolset 14.33.31629 contains MSVC 19.33.31629.0. So I conclude that something goes wrong.</p>
  <p>After this, I can modify the project and execute the &quot;Reload CMake Project&quot;, and CLion does it well because the versions of compilers are already configured.</p>
  <p>Specifying C and C++ compilers for the toolchain (File | Settings | Build, Execution, Deployment | Toolchains) doesn't help.</p>
  <p>When I remove the latest toolset using Visual Studio Installer, it also automatically removes C++ CMake Tools for Windows, which doesn't allow me to use CMake with Visual Studio.</p>
  <h1>Build</h1>
  <p>My <code>main.cpp</code> file is</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  
  int main() {
      std::cout &lt;&lt; _MSC_VER &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  <p>When I configure the project (no matter with CLion or manually) and build it using CLion GUI, I get the answer</p>
  <pre><code>1933
  </code></pre>
  <p>Although, if I use the same command as CLion, namely</p>
  <pre><code>&quot;C:\Program Files\CMake\bin\cmake.exe&quot; --build F:\test_project\build --target test_project --config Debug
  </code></pre>
  <p>I get what I need</p>
  <pre><code>1931
  </code></pre>
  <p>The strange part is that I get the correct result using Terminal even after configuring the project using CLion GUI. Also, I can set up the project in Terminal to use the newer toolset (which is the default) and have the <code>1933</code> printed.</p>
  <p>Also, when I debug the code using CLion, the Evaluate says that <code>_MSC_VER</code> is <code>1933</code> but the application still prints <code>1931</code>. When I create a variable <code>int x{_MSC_VER};</code>, the debugger shows that <code>x</code> equals <code>1931</code>.</p>
  <h1>Summary</h1>
  <p>If I use CLion GUI to configure or build the project or to do both things, it uses MSVC 19.33.31629.0.
  If I configure and build the project in CLion's Terminal using the same commands CLion shows me when configuring and building the project, I can use MSVC 19.31.31107.0.</p>
  <p>Am I missing something? Does CLion specify environment variables I should override? Is it possible to choose the MSVC version I need using CLion?</p>