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.
- Under the Project menu, choose Export Template…
- Leave the choice of Project Template selected and click “_Next >_”
- 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.
- Click Finish to generate your template.
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:
Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com