# CMake 4.2.3 picks wrong MSVC?

**URL:** https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572
**Category:** Usage
**Tags:** os:windows, comp:msvc, gen:vs
**Created:** [March 23, 2026, 12:56pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572 "2026-03-23T12:56:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![exoosh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/exoosh/32/4077_2.png) [@exoosh](https://discourse.cmake.org/u/exoosh)
#### Post date: [March 23, 2026, 12:56pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/1 "2026-03-23T12:56:47Z")

</div>

Hi,

so today I tried to build a project where we used to rely on the fact that CMake uses the ambient environment to figure out the compiler to use.

Alas, despite being started in the VS2022 Developer Powershell, it ends up picking VS2026 which is also installed on the system. What gives?

 ![image](https://discourse.cmake.org/uploads/default/original/2X/0/03f1c985025f32028996d8e4f983913a293f069c.png)

Was our original premise wrong and it doesn’t actually pick it from the environment even though it’s readily available there? I am fairly certain this used to work at some point.

Thanks for any insights.

PS: the installed CMake is the latest one as per WinGet, which is why it’s this one and not 4.3.0.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [March 23, 2026, 3:22pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/2 "2026-03-23T15:22:23Z")

</div>

Not all generators depend on the environment. You selected none and VS generator is the default which detects it from registry values.

---

<div class="post-metadata">

### Author: ![LegalizeAdulthood](https://discourse.cmake.org/user_avatar/discourse.cmake.org/legalizeadulthood/32/5282_2.png) [@LegalizeAdulthood](https://discourse.cmake.org/u/LegalizeAdulthood)
#### Post date: [March 23, 2026, 4:27pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/3 "2026-03-23T16:27:30Z")

</div>

My experience has been that CMake always picks the newest version of VS installed that it can detect. If you want a specific version of VS you specify it explicitly in the generator.

---

<div class="post-metadata">

### Author: ![exoosh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/exoosh/32/4077_2.png) [@exoosh](https://discourse.cmake.org/u/exoosh)
#### Post date: [March 23, 2026, 4:49pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/4 "2026-03-23T16:49:16Z")

</div>

Thanks for the responses!

Sigh, so I guess the premise was wrong. Giving an exact version of VS to generate for defeats the purpose, too.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [March 23, 2026, 5:14pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/5 "2026-03-23T17:14:48Z")

</div>

If you use the Ninja generator, it will use the environment.

---

<div class="post-metadata">

### Author: ![exoosh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/exoosh/32/4077_2.png) [@exoosh](https://discourse.cmake.org/u/exoosh)
#### Post date: [March 23, 2026, 5:41pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/6 "2026-03-23T17:41:00Z")

</div>

Thanks, I understood that. Unfortunately that’s still not equivalent to how it works with the VS generator due to property sheets and such …

---

<div class="post-metadata">

### Author: ![ChrisJaquet](https://discourse.cmake.org/user_avatar/discourse.cmake.org/chrisjaquet/32/304_2.png) [@ChrisJaquet](https://discourse.cmake.org/u/ChrisJaquet)
#### Post date: [March 26, 2026, 6:55am UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/7 "2026-03-26T06:55:08Z")

</div>

Something else you may want to keep in mind when using different Visual Studio environments is that you may want to use specific versions of the Windows SDK. I currently set that using the `CMAKE_SYSTEM_VERSION` variable:

```auto
cmake -G "Visual Studio 18 2026" -DCMAKE_SYSTEM_VERSION=10.0.26100.0

```

or

```auto
cmake -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_VERSION=10.0.19041.0

```

etc.

---

<div class="post-metadata">

### Author: ![exoosh](https://discourse.cmake.org/user_avatar/discourse.cmake.org/exoosh/32/4077_2.png) [@exoosh](https://discourse.cmake.org/u/exoosh)
#### Post date: [May 20, 2026, 1:48pm UTC](https://discourse.cmake.org/t/cmake-4-2-3-picks-wrong-msvc/15572/8 "2026-05-20T13:48:17Z")

</div>

> [@LegalizeAdulthood](#):
>
> My experience has been that CMake always picks the newest version of VS installed that it can detect.

FYI: this is not the case. It picks the newest _major_ version (e.g. 2022 if you asked for that). [But it _will not_ pick the latest version out of the installed instances of VS2022.](https://gitlab.kitware.com/cmake/cmake/-/work_items/27831)

Also it will use the newest version the specific version of CMake _knows_ about. So if you have an old enough version, that’d be VS2022 getting picked albeit VS2026 may be installed, whereas if you have the most recent version and you always relied on the (unstable!) default generator, the two facts that you installed VS2026 and updated to a version _knowing about_ VS2026 is enough to switch over to VS2026.
