# Visual Studio Generator EXCLUDE\_FROM\_ALL behavior

**URL:** https://discourse.cmake.org/t/visual-studio-generator-exclude-from-all-behavior/15620
**Category:** Development
**Tags:** gen:vs
**Created:** [April 23, 2026, 5:07pm UTC](https://discourse.cmake.org/t/visual-studio-generator-exclude-from-all-behavior/15620 "2026-04-23T17:07:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dbs4261](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dbs4261/32/4938_2.png) [@dbs4261](https://discourse.cmake.org/u/dbs4261)
#### Post date: [April 23, 2026, 5:07pm UTC](https://discourse.cmake.org/t/visual-studio-generator-exclude-from-all-behavior/15620/1 "2026-04-23T17:07:32Z")

</div>

I am running into an issue with the VIsual Studio 17 2022 generator and I am not sure if this is the intended behavior. I have a project configured with CMake that uses FetchContent to fetch it’s dependencies. In my CLion IDE, I get a list of targets that are available to run. This includes targets from the subprojects added with FetchContent. This is fine, but they are not necessary to build my project, so all of my FetchContent calls have `EXCLUDE_FROM_ALL`. All of this is the same when I use the Ninja generator. However, I ran into an issue that wasted an entire day of mine before I reread the `EXCLUDE_FROM_ALL` documentation. When using Ninja, I can still have CMake build an excluded target, `cmake -B ./build/ -S . --target unnecessary`. However, when I do the same with the Visual Studio generator, I get an opaque error message: `MSBUILD : error MSB1009: Project file does not exist. Switch: unnecessary.vcxproj`. This seems to be because the solution file just does not have any references to the excluded targets. It took an entire day of debugging before I figured out this was a byproduct of a specific interaction between `EXCLUDE_FROM_ALL` and the Visual Studio generator. From the command line, I can build that target using `cmake -build ./build/_deps/subproject-build/ --target unnecessary`, however in CLion, the `unnecessary` target just will not work because it builds the target from the project’s build directory. Is there a way to fix this behavior, or at least produce a better error message when using the Visual Studio generator?
