Monday, January 13, 2014

A Project Template Wizard Via NuGet

It's hard to believe that more than a month has gone by since the pure F# MVC 5/Web API 2 and pure F# Nancy templates were released. One of the known issues with these templates was that they didn't appear in the Visual Studio Online Templates search. I'm happy to say that this issue has been resolved.


The approach taken to address this issue involved a custom implementation of IWizard and a simple WPF dialog. While I've created several of these in the past, until now it never seemed practical to create anything that could easily be reused.

There is now a NuGet package with ID MultiProjectWizard that can be used to provide multiple templates in a single VSIX without having to give up Online Template search functionality. Here are the steps (Note: These steps assume that you are using SideWaffle, though this NuGet package has no dependency on SideWaffle):

1. Setup your solution as if it were a multi-project template by placing each template in it's own folder with the *.vstemplate file named as MyTemplate.vstemplate. Include an _definitions folder in the parent folder and create a <language>.vstemplate file within it. See https://github.com/fsharp/FSharpCommunityTemplates/tree/master/VisualStudio/Mvc5/TemplatePack/ProjectTemplates/Web for an example of how to setup the folder structure.

2. Make the XML in the _defintiions/<language>.vstemplate file similar to the following and update the TemplateData appropriately.



3.Update the WizardData/Projects child elements appropriately. Each element represents one of the templates that was included in it's own folder in step #1. Here's a description of the attributes for the ProjectInfo element:

  • folderName = This is the name of the folder created in step #1 that is associated with the template. The IWizard implementation will look into this folder and try to find a file with a name of MyTemplate.vstemplate.
  • displayText = This is the text that will display in the WPF window for this particular template.
  • icon = There are two options for icon: "FSharp" and "Generic". If you choose F#, then the icon for that template with include the text "F#", else it will not.  

4. Install the MultiProjectWizard NuGet package. Note: This package includes DLLs such as EnvDTE and EnvDTE80. If your project already includes these DLLs, then you may need to remove the duplicate References after installing this package.

5. Lastly, add the MultiProjectDialog.dll and MultiProjectTemplateWizard.dll files as Assets to the source.extension.manifest file (as an Assembly with "File on filesystem" as the source):


You can now try out your template. If all has gone well, you'll see a screen that looks something like this:


8 comments:

  1. Hi, I wonder whether you have had trouble with your Templates for VS2013, in regard of loading a Wizard Assembly (ie MultiProjectTemplateWizard). I am finding that VS2013 Templates won't load an assembly that's included in the VSIX package, but of course it will if it were signed and in the GAC (nullifying the benefits of the VSIX method). This worked fine in VS2012. Thanks, John

    ReplyDelete
  2. Hi John, I haven't experienced this issue. Are you seeing the problem in custom VSIX packages that you are building or in one of the package on VSG such as http://visualstudiogallery.msdn.microsoft.com/39ae8dec-d11a-4ac9-974e-be0fdadec71b ?

    ReplyDelete
  3. Hi Daniel. It is my own custom VSIX installed Item Template (C#), not any of yours. So when you use your templates on VS2013, the Wizard DLL is found and loaded? It loaded ok in VS2012, but it refusing to load in VS2013. I do have a do-nothing test demo of the problem, would you be willing to try?

    ReplyDelete
  4. Just to clarify. It is my template that worked in VS2012 ok, but a similar newly constructed same in VS2013 does not.

    ReplyDelete
  5. Sure, shoot me an email at dmohl at yahoo.

    ReplyDelete
  6. Has there been any progress on this issue? I am having the same problem.

    ReplyDelete
  7. I've just now pushed an update that will hopefully resolve this issue. http://visualstudiogallery.msdn.microsoft.com/f1dae7fe-1ecc-4f1b-86b5-32a2970d012a

    ReplyDelete
  8. Did you ever discover what the issue was? I'm having the same problem when adding the F# web project as a web role.

    ReplyDelete