简体   繁体   中英

How to add multiple options in custom template Visual Studio 2019

I want to add multiple options inside a custom project template.

For example when you create a new project search web and select ASP.NET Web Application as shown below screenshot.

图一

Once you select that option click on Next and provide all the details like Project name, Location, Solution Name and click on "Create".

Here you get new options to create different types of web applications like Empty, Web Forms etc like the below screen shot.

图二

A similar kind of project template, I'm trying to create to provide multiple solutions that users can select.

In my case, user will select "Custom Project" as the project template and inside that template, there should be different options like "Custom Utility", "Custom UI", "Custom Component".

I went through different blogs and post about it but couldn't find anything on this topic. Everywhere it's explained how to add a project template with multiple projects eg. this on Linkedin , this on C# corner or this on MSDN .

What I really need is to add a project template with multiple types of solution options, not just multiple projects.

Unfortunately, this is not a built-in feature of visual studio when exporting project templates just by themselves. As Dai said, you will have to create a VSIX project that has a custom wizard UI with project templates. You can do this in either C# or Visual Basic. Note that this would take a lot of work on your end because you would probably have to do the UI from scratch and do your best to replicate what visual studio is using with built-in templates, though the default styling on the windows controls should hopefully match.

Luckily, Microsoft has an official walkthrough on the docs on how to do this. A key section is when they create the UserInputForm , which in your case would be the custom ui where the user can select the sub template:

public partial class UserSelectTemplateForm : Form
{
    public UserSelectTemplateForm ()
    {
        this.Controls.Add(...);
        //...
    }
    //...    
}

If you need additional help getting started you may also want to look at Microsoft's getting started with the VSIX project template docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM