Visual Studio 2022 Project Templates for C++

OK the Microsoft documentation seems a bit thin so I'll spell it out after taking over half a day to get it right.

A 'project template' is a short cut to getting a Visual Studio project up and running. I like them. It's just that the ones supplied aren't quite right for me.
So I'll roll my own...

These are the steps I ended up with to make a simple Win32 Windows C++ desktop program.

You will need to change the files and folders I refer too to the ones in your project.

Create the thing you want to template as a VS project. Call it xname or something odd so it's easy to spot when editing,
You may have to fiddle about a bit with resource names.
Run Project | Export Template
The creates a zip file called xname.zip in
   C:\Users\nigel\Documents\Visual Studio 2022\My Exported Templates
that will work but can be improved on a lot.

Open it up into a temp folder and edit the file xname.vcxproj
notepad will do or any simple text editor that can handle 8 or 16bit character sets.
Change all references to xname into $safeprojectname$

Now edit the files xname.cpp, xname.rc and resource.h using $safeprojectname$ for xname and $year$ for the copyright year.

Now edit the file MyTemplate.vstemplate

Below </ProjectSubType> add the tags VS searches on
   <LanguageTag>C++</LanguageTag>
   <PlatformTag>Windows</PlatformTag>
   <ProjectTypeTag>Desktop</ProjectTypeTag>


Now down in the <TemplateContent> section:
This renames the files so the value is left as xname.something but
the TargetFileName= becomes $safeprojectname$.something

Also change ReplaceParamaters="false" to "true" for all the files where you want the text substitutions to be made. In my case that's the .cpp, the .rc and resource.h

Rezip it and copy it back but specifically delete the previous version before you copy in the new. I had problems here so I suspect there is something about the time stamping that is needed to get a reload.
   C:\Users\nigel\Documents\Visual Studio 2022\My Exported Templates
and to
   C:\Users\nigel\Documents\Visual Studio 2022\Templates\ProjectTemplates

Here is one of my simple ones for you to pick apart DesktopTemplate.zip



by Nigel Hewitt
Hit counter