Search code examples
templateswizardvisual-studio-extensionsenvdte

Regarding VS2010 Multi solution project template


In VS2010, I have created a custom multi-solution project template and implemented IWizard to replace custom parameters in the Project.

I would like to know if in the Wizard I give an option to select an additional project that needs to be added to existing template such as test project.

How can I handle this in code? On which method of IWizard implementation will I add a new project.


Solution

  • You can programmatically add additional projects to the ones defined in the multi-project template.

    Something like this:

    public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
    {
        var solution = (Solution2)((DTE2)automationObject).Solution;
        var template = solution.GetProjectTemplate("Folder\\TestProject.zip", "CSharp");
    
        string destinationFolder = "...";
        string projectName = "..."
        solution.AddFromTemplate(template, destinationFolder, projectName, false);
    }
    

    You probably want to move the code to another method to RunStarted, but this is roughly how I do it. I actually use a completely empty set of projects in the multi-project template however, and trigger all the project templates like this.

    One requirement (I think) is that the project needs to be present in one of the usual template folders, which means it's also available to be added individually. This could be an advantage or a disadvantage for you, but your Wizards will need to be able to deal with that in some way.

    I've been meaning to do a Blog post about this and some other templating stuff, unfortunately I haven't found the time yet. Perhaps I should put it a bit higher on the priority list...