none
Custom Project Type VSPackage\Template: How do I connect a VS Project Template to my Custom Project Type?

    Question

  • I have been maintaining a custom project type VSPackage in C# for some time that created its own separate category in the New Project Creation wizard on the same tree level under "Templates" as "Visual C#". The package was originally written for VS2005, and has been upgraded over the years to support new versions of Visual Studio. It currently supports VS2013 using the VS2012 SDK.

    I am trying to upgrade my new project creation from using .vsdir, .vsz , and EnvDTE.IDTWizard to using vstemplates with an accompanying IWizard since this is the new direction VSX has taken and Visual Studio is not afraid to drop support of old methods.

    I am having trouble connecting the vstemplate to the custom project type.

    If I use the "CSharp" type in the vstemplate <ProjectType> element, I can see my custom template and run the wizard, but it understandably puts the template under C#. If I try it with my custom project type, the devenv log says that it can't find the project type:

    "Error in Template (), file (MyProjectTemplate.vstemplate).  Unregistered ProjectType (MyProject)."

    I have two questions:

    1. Is it possible, with this new way of creating and launching project wizards, to have a custom project type with accompanying template and wizard that isn't a sub-type of CSharp or some other built in type? 

    2. How is the Type that I specify in the vstemplate <ProjectType> element defined in the Custom Project Type Package or package registration? Is there a fundamental change to the registration of a new project type that I need to take into account?

    I have looked through a lot of MSDN documentation, and tried a number of different things, but in the end I can't get past this fundamental issue so any help would be greatly appreciated.

    Tuesday, January 02, 2018 7:30 PM

Answers

  • The .vstemplate manifest will have a <ProjectType> entry, which is what ties the template to your particular project type. This should align with the name you pass to the ProvideProjectFactoryAttribute, on your VSPackage class.

    The old MPF_Proj sample codebase used an old .vsz based template and the projectTemplatesDirectory argument of the ProvideProjectFactoryAttribute, but I recommend just setting that to NULL, as that was for the older .vsz based templates.

    I wrote a simplified and updated MPF_Proj based project type called "Simple Project" that includes a project and item template, a couple years back, all deployed by the same .VSIX, which you might find useful as a guide.

       https://github.com/EdDore/VSXArcana/tree/master/SimpleProject

    Cheers,


    Ed Dore

    Tuesday, January 02, 2018 8:23 PM
    Moderator

All replies

  • The .vstemplate manifest will have a <ProjectType> entry, which is what ties the template to your particular project type. This should align with the name you pass to the ProvideProjectFactoryAttribute, on your VSPackage class.

    The old MPF_Proj sample codebase used an old .vsz based template and the projectTemplatesDirectory argument of the ProvideProjectFactoryAttribute, but I recommend just setting that to NULL, as that was for the older .vsz based templates.

    I wrote a simplified and updated MPF_Proj based project type called "Simple Project" that includes a project and item template, a couple years back, all deployed by the same .VSIX, which you might find useful as a guide.

       https://github.com/EdDore/VSXArcana/tree/master/SimpleProject

    Cheers,


    Ed Dore

    Tuesday, January 02, 2018 8:23 PM
    Moderator
  • Thanks for the response! I tried just matching the project factory name, but that didn't fix my issue. There are probably some other details I'm missing. I'll look at your code example and see if I can figure it out. One hitch is that I'm using the VS2012 SDK, but "MPF for Projects - Visual Studio 2012" doesn't have a download, so I can't convert your example over to verify that it works with the SDK I'm using. I'll get the VS2013 SDK and try that.

    Wednesday, January 03, 2018 9:44 PM
  • Okay, I was finally able to test your code, and saw that it does do what I am trying. I went back and double checked my changes based on your code, and was able to get it working! I'm not sure why it didn't work before. It could be that my environment was in a funny state. Either way, I really appreciate the help!
    Thursday, January 04, 2018 12:16 AM
  • My pleasure. 

    FWIW, the VS 2012 version of the MPF_Proj sample code base, can be found here:

       http://mpfproj11.codeplex.com/

    Cheers,


    Ed Dore

    Sunday, January 07, 2018 12:12 AM
    Moderator