5

How do I share a precompiled header across multiple projects in the same solution in Visual Studio 2019?

As a requirement, I do not want to create a project just to compile the precompiled header, which then is included and referenced by other projects.

I know the feature simply didn't exist in the past and you'd have to use a pre-build event to copy the actual output file for it to each other project. Since VS has changed a lot over the years, I figure it's time to reask this question because there's no information immediately available on google.

I was looking at this question but it seems that it isn't viable in a production environment.

Or is there something better using C++20 modules?

nowi
  • 437
  • 4
  • 13

1 Answers1

0

As far as I concerned, you should need a SharedPCH, it is building the pch and the static library. When ConsoleApplication projects reference the SharedPCH one, the build will automatically link the SharedPCH’s static lib, but several project properties need to be changed as well. As those properties need to be changed similarly for all projects, I suggest you could create the SharedPCH.props and CustomBuildStep.props files and imported them to your projects using the Property Manager tool window.For more details I suggest you could refer to the Blog

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20