Cool Visual Studio 2017 Tip #4 : Templates

I was recently watching an interesting C#7 video by Jesse Liberty and noticed that within it, he was using his own project type to demonstrate the new features of the language.

That seemed really useful so here I’m going to show you how you can do something similar using existing features of Visual Studio. I’ll be using version 2017 but it wouldn’t surprise me if this existed in prior versions too.

OK, so what do I want to achieve? I’d like to create a project which is console based, uses the .NET framework and comes with a baked in class called Runner to execute code, much like Jesse’s. I also want to hook everything together so that I can run it immediately if I choose to.

The first step is to create something just like that but here’s mine in case you’re wondering:

Don’t forget to save your project before you move onto the next step.

  1. Under the Project menu, choose Export Template…
  2. Leave the choice of Project Template selected and click “Next >
  3. On the screen that appears, give the template a name, add a description and if you like, choose icon and preview images. Everything else can be left as is. In my case, I named my project as ConsoleRunner so I didn’t want to change that name.
  4. Click Finish to generate your template.

Where are the templates stored?

After clicking Finish, you will be presented with the folder in which the template has been added. On my machine that’s here:

C:\Users\[user name]\Documents\Visual Studio 2017\My Exported Templates

As you can see, the template is stored as a zip file, but what’s inside?

Now, when you go to create a project, you have this new option:

And if you click on it, you can see the description you may have added:

twittergoogle_plusredditpinteresttumblrmail

Written by Stephen Moon
email: stephen at logicalmoon.com
www: https://www.logicalmoon.com


Leave a Reply

Your email address will not be published. Required fields are marked *