dotnet / templating

This repo contains the Template Engine which is used by dotnet new
https://docs.microsoft.com/dotnet/
MIT License
1.61k stars 368 forks source link

Announcement: adding Template Engine templates to VS2017 #1209

Closed sayedihashimi closed 6 years ago

sayedihashimi commented 7 years ago

FYI I've been working on getting support for to add Template Engine templates in the Visual Studio New Project Dialog. This is SideWaffle 2017, the code can be found at https://github.com/ligershark/sidewafflev2.

I have created a 10 minute video showing how to add Template Engine projects to VS2017. In the video I also show multi-project templates.

It would be great if you guys can try this out and let me know i it works for you.

I'll close this issue in a few days, or when comments die down if we get any replies here.

dansiegel commented 7 years ago

@sayedihashimi you referenced a video, but the link takes you to the GitHub repo, and it's not referenced in the ReadMe.

dansiegel commented 7 years ago

also I'd be super interested in seeing this for VS4Mac as well, especially for more complex templates that need a custom dialog.

sayedihashimi commented 7 years ago

@dansiegel sorry about that. I've fixed it. Link is https://youtu.be/g6az_N95dVM.

also I'd be super interested in seeing this for VS4Mac as well, especially for more complex templates that need a custom dialog.

Yes, this is one of my follow up points. I would like to discuss with @mhutch to see how we can support VS4Mac as well here.

mhutch commented 7 years ago

@sayedihashimi you can use these templates in VS for Mac today, you simply need to register them via an extension (just like VS)

https://github.com/mono/monodevelop/blob/master/main/src/addins/MonoDevelop.AzureFunctions/Properties/Manifest.addin.xml#L15 https://docs.microsoft.com/en-us/visualstudio/mac/extending-visual-studio-mac-walkthrough

sayedihashimi commented 7 years ago

@mhutch what would the VS4Mac user install? For VS we have .vsix, what's the equivalent in VS4Mac?

sayedihashimi commented 7 years ago

Ignore my previous comment I see the info is in the second link. I'll take a look. I'm on vacation now so maybe when I get back.

mhutch commented 7 years ago

The extension file would be an 'mpack' which can be installed from the extension gallery or from a file.

Let me know if you have any questions about creating extensions when you get back :)

joeaudette commented 7 years ago

Hi, Thanks for this! I have had good success creating a template that works well with dotnet new and supports a set of choices. Then I followed your youtube video and created a vsix. It launches the test version of VS just the same as in your video and my template appears in VS I am able to create a project. However, in VS I don't see any of the options for my template so it only creates a project with the default values for template parameters.

How can I make the same options that are available when using dotnet new also available in VS 2017 when creating a project? Is there any documentation or tutorials that would help me do that?

Thanks!

sayedihashimi commented 7 years ago

in VS I don't see any of the options for my template so it only creates a project with the default values for template parameters.

That is the default behavior.

To expose your options you'll need to create a new custom wizard and add that to the .vstemplate to run before the TemplateEngine wizard.

See my comments on a similar issue at https://github.com/ligershark/sidewafflev2/issues/17#issuecomment-327677764. I have a sample that shows how this works in this folder. Later I'll move that to https://github.com/dotnet/dotnet-template-samples after I clean it up.

joeaudette commented 7 years ago

Thanks very much! Got it working nicely with a custom form launched from the wizard to let the user choose options.

sayedihashimi commented 7 years ago

Is your project open source, if so link?

joeaudette commented 7 years ago

@sayedihashimi yes, my template repo is here https://github.com/joeaudette/cloudscribe.templates Next up I will work on publishing a nuget for dotnet new command and the vsix in the Visual Studio Gallery as well as documentation that will go below here: https://www.cloudscribe.com/docs Up till now I have been steering people towards my Starter Kits repo but now the project template will be an even better way for people to start new projects with my cloudscribe libraries. I am really happy that you guys made this not only possible but relatively easy. Great work!

joeaudette commented 7 years ago

when I try to upload my .vsix file to Visual Studio Gallery I get an error: "Your extension type does not match the VSIX type. It should be uploaded as a Tool"

joeaudette commented 7 years ago

seems to work after choosing tool instead of project template

joeaudette commented 7 years ago

managed to publish my vsix https://marketplace.visualstudio.com/items?itemName=joeaudette.cloudscribeProjectTemplate had to choose tool as the type rather than template, but it is working!

sayedihashimi commented 7 years ago

@joeaudette that's great, congrats. Are you going to roll in the starter kits from https://github.com/joeaudette/cloudscribe.StarterKits as well? It should be pretty straightforward.

joeaudette commented 7 years ago

@sayedihashimi yes, that is what I have done but I did it all with one template and conditional logic based on template parameters so my template can basically create projects with the different configurations that correspond to the starter kits. I uploaded the nuget so now people can use either the dotnet new CLI or the vsix if they use VS 2017 https://www.nuget.org/packages/cloudscribe.templates/1.0.0 dotnet new -i "cloudscribe.templates::*" and then dotnet new cloudscribe --help shows the available parameters

Tomorrow I will make documentation on my site to encourage people to use the template instead of the starter kits for starting new projects.

sayedihashimi commented 7 years ago

@joeaudette that's fantastic, really great to hear. If you could email me your thoughts on your experience creating templates it would be appreciated. My email is sayedha@microsoft.com.

neman commented 7 years ago

What should I do when I have already created template by hand, following this link https://blogs.msdn.microsoft.com/dotnet/2017/04/02/how-to-create-your-own-templates-for-dotnet-new/ ? I created internal NuGet package, and it's used in production, by client, to create REST services. I do not have this template.vstemplate file. Do I have to map some properties from template.json file? Is it just like old template.vstemplate which is used as metadata for VS (language, node...)?

And what is the point of creating NuGet package for template since its not usable with VS? I created NuGet, but now I need to create VSIX and to maintain VSIX feed. Will it be possible, in foreseeable future ,to install template from NuGet server from VS and that it will be available to choose when doing File -> New Project?

sayedihashimi commented 7 years ago

@neman if you already have an existing NuGet package, you can use that. There are two steps:

  1. Add existing .nupkg file to .vsix file
  2. Create a .vstemplate

The .vstemplate is needed to populate the VS New Project Dialog and to invoke your template. In the .vstemplate the CustomParameter for GroupID must match the groupIdentity in template.json and $language$ must match the language tag in template.json.

From the .vstemplate they are

<CustomParameters>
  <CustomParameter Name="$language$" Value="CSharp" />
  <CustomParameter Name="$uistyle$" Value="none"/>
  <CustomParameter Name="$groupid$" Value="SideWafflev2.TemplatePackProject" />
  <CustomParameter Name="SideWaffleNewProjNode" Value="CSharp\Extensibility\SideWaffle"/>
</CustomParameters>

See template.json and sidewaffle.vstemplate

If you need more help on that please file an issue at https://github.com/ligershark/sidewafflev2/blob/master/templates/SideWaffle.Template/.template.config/sidewaffle.vstemplate so that we can discuss more details there.

And what is the point of creating NuGet package for template since its not usable with VS? I created NuGet, but now I need to create VSIX and to maintain VSIX feed.

Yes it would be better if we could directly consume the latest NuGet package without having to create the .vstemplate/.vsix. The good thing is that the .nupkg itself can be included so you have a single source of truth.

Will it be possible, in foreseeable future ,to install template from NuGet server from VS and that it will be available to choose when doing File -> New Project?

Not in the foreseeable future, but that is something that I would love to see. My first priority was that we can have a single source of truth for a template. In this model that's the .nupkg, and it can be shared across cli/vs/vs4mac. If we get a good amount of templates created, then I will have a good amount of data to try and get a better integrated solution. Right now there is not enough demand for me to make such a proposal.

neman commented 7 years ago

Ok, I'll try NuGet template with VSIX and report results.

brianlagunas commented 6 years ago

How do you add an existing template NuGet package that was created by hand, without the SideWaffle extension, to an existing VSIX project?

I have an existing VISX project that contains multiple project templates for multiple platforms. Now I want include a new template based off the "dotnet new' to ship with this same VISX. So far, it looks like you have to use the SideWaffle extension to create the VSIX because of all the magic in the .proj and .targets files.

Can I just add a new C# project template project to my existing solution, add the template NuGet as content to it, and then modify the .vstemplate file some how?

Thoughts?

sayedihashimi commented 6 years ago

@brianlagunas if you have an existing VSIX and .nupkg there are a few steps needed:

If the .nupkg changes you'll need to update the file in the vsix, and the same goes for the .zip of .vstemplate. I think that's all that is needed but I could be forgetting something. I also made a video describing how SideWafflev2 works, it may have some additional useful info https://youtu.be/5Cb4vOh5Eog.

panmona commented 6 years ago

Why can't VS17 use the templates that are installed in dotnet new for new projects? This here seems to be way too complicated to make it possible to also create a project from the GUI. Would be a great addition.

mlorbetske commented 6 years ago

@maracuja-juice we’re working towards making that happen, though some of the information about how to present the templates in the project creation UI in Visual Studio is not currently natively available here (like how many nodes above the exact category to show the templates in should also display it). There are portions of VS that can use this format natively, like the dialog for creating .NET core web projects or the Azure Functions project or item template dialogs, but for the time being it remains required to register templates to VS via the VSTEMPLATE file.