Conditionally include .cpp file per Configuration|Platform and hide it completely from Solution Explorer
04:37 16 Feb 2026

I’m using MSVC with a .vcxproj project.

I want a specific file (xyz.cpp) to:

  • Be included only for a specific Configuration|Platform (e.g. Debug|x64)

  • Be completely absent in other configurations

  • Not appear in Solution Explorer

  • Not be searchable in the project when not active

I do not want to use because the file still shows up in the editor and search, which creates noise.

So far I tried conditioning the ItemGroup in the .vcxproj:


  

However:

  • Switching configurations does not update the UI

There are no other explicit references to xyz.cpp in the project file (as far as I can see).

Question:

What is the correct way in a C++ .vcxproj project to conditionally include a source file so that it is completely hidden from the project (including Solution Explorer) when the configuration/platform condition does not match?

Is this even supported reliably by the VC project system?

visual-studio msbuild msbuild-task vcxproj