# CMakePresets.json example for Visual Studio

**URL:** https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701
**Category:** Usage
**Created:** [December 22, 2023, 9:01pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701 "2023-12-22T21:01:26Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jaquilio](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaquilio/32/3789_2.png) [@jaquilio](https://discourse.cmake.org/u/jaquilio)
#### Post date: [December 22, 2023, 9:01pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/1 "2023-12-22T21:01:26Z")

</div>

I am looking for a good example of CMakePresets.json file used for building with Visual Studio. Can anybody please share theirs?

Thanks!

P.S. I did search online, but, only found some toy preset files and not any corresponding to serious software projects.

---

<div class="post-metadata">

### Author: ![AnthonyD973](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anthonyd973/32/3130_2.png) [@AnthonyD973](https://discourse.cmake.org/u/AnthonyD973)
#### Post date: [December 26, 2023, 5:41pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/2 "2023-12-26T17:41:03Z")

</div>

Not sure if that’s what you are looking for, but [here](https://github.com/adentinger/CMakeBestPractices/blob/a2d806954241df9f671163cf9c1b13e2966208cf/prj1/CMakePresets.json) is one I’ve written and which [works with multi-config generators like VS](https://github.com/adentinger/CMakeBestPractices/actions/runs/7325456331/job/19950060181). This presets file includes another one in the parent directory which contains more stuff, but in most situation you’d probably want to only have one.

---

<div class="post-metadata">

### Author: ![jaquilio](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaquilio/32/3789_2.png) [@jaquilio](https://discourse.cmake.org/u/jaquilio)
#### Post date: [December 26, 2023, 11:35pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/3 "2023-12-26T23:35:14Z")

</div>

Thanks! Do the build presets appear as choices for you in Visual Studio GUI? For me, they don’t.

I just now placed your CMakePresets.json in my folder and I still don’t see any drop-down list or anything like that on the Visual Studio 2022 GUI that would let me select the build preset to use.

---

<div class="post-metadata">

### Author: ![AnthonyD973](https://discourse.cmake.org/user_avatar/discourse.cmake.org/anthonyd973/32/3130_2.png) [@AnthonyD973](https://discourse.cmake.org/u/AnthonyD973)
#### Post date: [December 26, 2023, 11:50pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/4 "2023-12-26T23:50:16Z")

</div>

I don’t usually open the created Visual Studio projects (the logs are usually enough in my use-cases), and I tend to set the build type and/or build config on the command-line or with environment variable, so I can’t give a definite answer. However, I’ve just found [this SO answer](https://stackoverflow.com/a/71299158/2252948) that seems to refer to what you’re talking about. Let me know whether that answers your question.

---

<div class="post-metadata">

### Author: ![jaquilio](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaquilio/32/3789_2.png) [@jaquilio](https://discourse.cmake.org/u/jaquilio)
#### Post date: [December 26, 2023, 11:58pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/5 "2023-12-26T23:58:24Z")

</div>

What I had already tried was something similar to what is suggested in that stack overflow response, i.e. I had added some buildPresets and I had also set the “configuration” field of those buildPresets. I would have now expected the buildPresets to show up as a drop-down list (or something similar) on the GUI. But, they don’t.

---

<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: [December 27, 2023, 1:11pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/6 "2023-12-27T13:11:46Z")

</div>

Maybe there’s a misunderstanding. With Visual Studio you have two distinct choices:

1. Let CMake create a solution. This generator offers configurations like Release and Debug in the IDE, nothing more.
2. Open the preset json file from the IDE. This let’s you choose from the presets that are usually done with ninja single configuration generator.

---

<div class="post-metadata">

### Author: ![jaquilio](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaquilio/32/3789_2.png) [@jaquilio](https://discourse.cmake.org/u/jaquilio)
#### Post date: [December 27, 2023, 7:10pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/7 "2023-12-27T19:10:47Z")

</div>

I am not explicitly asking Visual Studio to create a solution. As suggested on Visual Studio’s web page, I am using the “Open a local folder” option and choosing the folder containing the root CMakeLists.txt file and CMakePresets.json file.

This has been working fine when I had only “configurePresets” in the presets file (no buildPresets). That is, the different configure presets used to show up as a drop down list in the GUI.

Then, I felt a need to add buildPresets to the file. When I did that, neither the configurePresets nor the buildPresets show up in the GUI.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 27, 2023, 7:38pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/8 "2023-12-27T19:38:56Z")

</div>

Perhaps your `CMakePresets.json` file has an error somewhere. From a command line, try running `cmake --list-presets=all`. If that works, then I’d be filing a bug with the Visual Studio folks.

---

<div class="post-metadata">

### Author: ![jaquilio](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaquilio/32/3789_2.png) [@jaquilio](https://discourse.cmake.org/u/jaquilio)
#### Post date: [December 27, 2023, 8:24pm UTC](https://discourse.cmake.org/t/cmakepresets-json-example-for-visual-studio/9701/9 "2023-12-27T20:24:57Z")

</div>

Indeed, there was an error in the presets file. The configuration preset referenced in a buildPreset didn’t exist because of a name mismatch due to a typo.

Weirdly, Visual Studio was not showing any message about there being an error. But, running the “cmake --list-presets=all” command you suggested indicated the error.

Thanks!
