Friday, 26 January 2018

How to create custom file templates in Visual Studio

In my last post, I explained how to create a C project in Visual Studio. But can you also add new C files by clicking icons in the New Items dialog? Well, yes, you can – but you will have to create your own custom file templates first. This video shows how to do that…

When you’ve saved a template it is added to two directories beneath the \Users folder. For me these are:

C:\Users\Huw\Documents\Visual Studio 2017\My Exported Templates
C:\Users\Huw\Documents\Visual Studio 2017\Templates\ItemTemplates

I had a few problems when adding file item templates. Sometimes the newly added templates weren’t appearing in Visual Studio. I found that an easy way to fix this is to delete the template cache. That’s the entire \ItemTemplatesCache directory here:


Then I restarted Visual Studio and all my new templates appeared in the New Item dialog.