Iris Classon
Iris Classon - In Love with Code

Visual Studio 2017 templates and the missing content

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.

C:\Users[USER]\AppData\Roaming\Microsoft\VisualStudio\15.0_ab2f93a7\ProjectTemplatesCache\

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.

 

Comments

Leave a comment below, or by email.
Alexander
12/7/2018 7:31:35 PM
You have saved my day! Or even a couple of days.
Surprisingly, but this issue is still not solved in VS2017, and the most confusing part that it works selectively for some files and doesn't work for other files with no clear indication of a reason. 
Alessandro Faustini
3/6/2019 11:16:31 AM
Thanks, you saved my day ^_^ 
Iris Classon
3/6/2019 12:52:36 PM
Reply to: Alessandro Faustini
No problem! Glad I could help :) 


Last modified on 2017-06-14

comments powered by Disqus