As we are slowly migrating our solution, a group of microservices, to .NET Core I decided to throw together a template with boilerplate code that we want to keep within the project. But, for some odd reason the templates I created wouldn’t show any content when I created a project based on them.
OBS! The templates I’m talking about aren’t templates created to be used with the new templating engine. I’ll write a separate post on that =)
Here is an example (tested on two different machines, with fresh installs of Visual Studio 2017) with a console app:
I created a console application
I added a folder and a class file with a method
I then exported the project as a template, making sure that is directly imported into Visual Studio so it will show up as an option when I want to create a new project.
First it wouldn’t even show up.
I ran installvstemplates in the Developer Command Prompt, but no luck.
So I navigated to the cache- which was missing and therefore I manually created the ProjectTemplatesCache folder.
I then restarted Visual Studio, and voila I could choose the template.
But, to my dismay, the project was completely empty- the content was missing!
I looked at other project templates, those that come with Visual Studio, and compared the template files. I think I had tried most tags at some point, until I decided to add the CreateInPlace tag. According to the documentation this tag should be optional, and default to true. But, it turns out that adding this tag, and setting it to true, solved the missing content problem. Setting it to false did not- in case you wonder.
I have to admit that I don’t understand why this tag is required, and if it indeed it is but isn’t created then it’s a bug. I’ll dig a bit deeper, let me know if you know if I’ve missed something 🙂
From the docs:
Specifies whether to create the project and perform parameter replacement in the specified location, or perform parameter replacement in a temporary location and then save the project to the specified location.
CreateInPlace is an optional element. The default value is true.