How to create an Item Template Category using VSIX deployment when referencing an Item Template project?

Answered How to create an Item Template Category using VSIX deployment when referencing an Item Template project?

  • Friday, August 26, 2011 5:14 PM
     
     

    I know that you can have your custom Item Templates appear in custom categories in the "Add new file...." dialog by creating your Item Template zip file, and placing it in "C:\Users\[UserName]\Documents\Visual Studio 2010\Templates\ItemTemplates".  So for example, if I wanted all of my company's custom item templates to show up in an "iQmetrix" category, I would place the item template zip file in "C:\Users\[UserName]\Documents\Visual Studio 2010\Templates\ItemTemplates\iQmetrix".  Then in the "Add new file..." dialog my template would show up under Visual C# -> iQmetrix, instead of directly under Visual C#.

    The problem with this is that it requires the user to manually copy/paste the item template zip file into the correct location.  So instead I want to have a VSIX package install our custom item templates automatically.  So I created a new solution that has a VSIX project and a few Item Template projects, so when I build the solution it packages the item template projects up into the VSIX file.  When using this method, it doesn't install the item templates to "C:\Users\[UserName]\Documents\Visual Studio 2010\Templates\ItemTemplates".  When I do "Add Content" in the VSIX manifest and reference the item template project directly, the item templates are always just under their language category (e.g. Visual C#).

    Instead of adding a "project" in the VSIX manifest, if I add a "file" (pointing it to the .zip file created by the item template project) then I am allowed to specify the "Add to subfolder (optional)" parameter, and putting "iQmetrix" in that field causes my Item Template to be added to an "iQmetrix" category like I want.  The problem is that the "Add to subfolder (optional)" parameter is disabled when directly referencing a project (rather than a file).  So how can I specify the category to place my item templates in when directly referencing the item template project?

    Thanks in advance!


    - Dan - "Can't never could do anything"

All Replies

  • Monday, August 29, 2011 10:10 PM
     
     

    Hi Dan

    The best way to package a template in a VSIX is to use the Export Template Wizard extension from the VS Gallery (find the extension at http://visualstudiogallery.msdn.microsoft.com/57320b20-34a2-42e4-b97e-e615c71aca24 and documentation at http://msdn.microsoft.com/en-us/library/ff527343.aspx).

    Hope this helps.

    Gary Horen
    Program Manager, Visual Studio Platform

  • Monday, August 29, 2011 10:25 PM
     
     

    Hi Gary, I actually tried using the Export Template Wizard before the more manual methods that I describe above.  The Export Template Wizard does not meet my needs:

    1 - It cannot package multiple Item Templates into a single VSIX package; it only allows one item template.

    2 - It does not allow me to create a custom category like I want (e.g. put all my Item Templates in an "iQmetrix" category).

    Since the extension hasn't been updated in a year and a half, I assume the project is dead?  So using the extension is not an option for me.  Any other help you can offer would be appreciated.  Thanks.


    - Dan - "Can't never could do anything"
  • Tuesday, August 30, 2011 8:09 AM
     
     

    Hi Gary,

    I just created an item template which is installed in a specific category but I did it manually. In the extension.vsixmanifest in the <Content> tag I added

    <ItemTemplate>ItemTemplates</ItemTemplate>

    ItemTemplates is the folder in the vsix where the item templates must be placed. In this folder I have a sub folder which in your case must be iQmetrix.

    So just put you item template in ItemTemplates/iQmetricx/yourItemTemplateName.zip

    I hope that this will help you.

     

  • Tuesday, August 30, 2011 5:11 PM
     
     

    Thanks for the post Dimitar.  I already knew the information you posted though.  In the VSIX project if you add the content as "file", then it puts it in the folders like you mention.  My problem is that when adding content as a "project" it does not create any folders or put the zip file anywhere that I can see, so I can't modify it's path (effectively modifying the category that it is placed in).

    If it is simply not possible to use custom categories when adding content as a "project", then the hack to make it work will be to use a post-build script to copy the generated .zip file from the Item Template project's bin folder to where I want it in the VSIX project (e.g. ItemTemplates/iQmetrix/TemplateName.zip), and use "add as file" instead of "project" in the VSIX project manifest.  I was just hoping to avoid doing this, and assumed that VS had a way to accomplish this without a hack.  I guess this is just one feature that got overlooked.


    - Dan - "Can't never could do anything"
  • Wednesday, August 31, 2011 5:52 AM
    Moderator
     
     Answered

    Hi Deadlydog,

    In your VSIX project, open the property of the item template project, you will find a item called VSIX sub path, which is the location the VS help copy the output of item template project to. Therefore change it to ItemTemplates\iQmetrix.

    You also can change it in MSBuild way, open your VSIX project in editor, search itemgroup for your item template project, and modify the following tag:

    <VSIXSubPath>ItemTemplates\iQmetrx</VSIXSubPath>

    Regards,

    Yi 


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Tuesday, September 06, 2011 3:41 PM
     
     

    Hi Yi Feng Li, thanks for the response, and sorry about taking so long to post back.  Your second method of directly modifying the VSIX project's .csproj file and changing the <VSIXSubPath> property works :)  However, this still feels a bit hackish, so if I can get it to work using only the VS GUI I would like that (since other developers will be doing this as well once I get the process flushed out).

    I'm confused about your instructions for the first method.  Am I supposed to look in the properties of the VSIX project, or the Item Template project?  In the Item Template project properties there is a tab called "VSIX", but when I check off "Create VSIX Container during build" or "Copy VSIX content to the following location" and enter "iQmetrix", I get the following compile error:

    ---------------------------------------------------------------------

    Source.extension.vsixmanifest file not found in project. If a file with this name is present in the project, make sure the build action is set to "None".

    ---------------------------------------------------------------------

    If I check off "Copy VSIX content to the following location" and enter "iQmetrix" in the VSIX project properties, then my item template just installs to the default location instead of into an "iQmetrix" category.

    If you could clarify your instructions for the first method that would be greatly appreciated :)  And since your second method technically does work, I'll re-mark your response as an answer once after I get a response back from you; since it doesn't feel right to mark an answer when my question isn't fully resolved yet.  Thanks!


    - Dan - "Can't never could do anything"
  • Wednesday, September 07, 2011 5:19 AM
    Moderator
     
     Answered

    Hi,

    Generally, these two methods are equivalent. The way you tried is for MSBuild script which is valid and also an MS recommend way.

     

    The first workaround is as following:

    1.       In your VSIX project, add a template project as Content via Manifest designer. You will find the template assembly will be added as the reference in solution explorer.

    2.       In solution explorer, click on the template reference which is added in step1 in Reference section, open the Properties pages for the template item.

    3.       In Properties page of the template reference, there is an item called VSIX Sub Path. This is the correct part we are looking for. We can change the path as we want to install the template.

     

    Hope the explanation clear for you.

     

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked As Answer by deadlydog Wednesday, September 07, 2011 2:52 PM
    •  
  • Wednesday, September 07, 2011 2:56 PM
     
     
    Thank you so much Yi Feng Li.  Even though both changes make the same change, I prefer this method as it allows developers to change everything from within the VS GUI so there's less chance of them mucking things up.  Thanks again!
    - Dan - "Can't never could do anything"
  • Monday, February 27, 2012 1:19 AM
     
     Proposed

    This is also one potential way of addressing the categorization while creating a VSIX project:

    http://samirvaidya.blogspot.com/2012/02/publishing-vsix-project-or-item.html

    • Proposed As Answer by vs2010junkie Monday, February 27, 2012 1:19 AM
    •  
  • Friday, February 01, 2013 8:15 PM
     
      Has Code

    Its a bit of a long shot re-opening an old thread but here goes:

    I am having exactly the problem described by this thread. When I read the clarified answer from Yi Feng Li I thought I was home and dry. I made the change in test projects in both VS2010 and 2012 each with the same result.

    I am now seeing my project template appear like this.

    What I would like to see is Visual C#->Assurity without the CSharp folder below it.

    This seems to relate to the output folder for my template project which in turn appears as far as I understand to relate to the Microsoft.VsSDK.Targets file and except of which is below.

    <!-- ======================================================================================================= TemplateProjectOutputGroup Used for determining the template zip file(s) that this project builds from another project ======================================================================================================= --> <PropertyGroup> <TemplateProjectOutputGroupDependsOn> $(TemplateProjectOutputGroupDependsOn); GetZipFilesFromVSTemplates; CalculateZipFiles </TemplateProjectOutputGroupDependsOn> </PropertyGroup> <Target Name="TemplateProjectOutputGroup" Outputs="@(TemplateOutputGroupOutput)" DependsOnTargets="$(TemplateProjectOutputGroupDependsOn)"> <ItemGroup> <_TemplateOutputGroupOutput Include="@(_ZipProject->'%(ZipFile)')" > <TemplateSubPath>%(_ZipProject.Language)\%(_ZipProject.OutputSubPath)\%(_ZipProject.Culture)</TemplateSubPath> </_TemplateOutputGroupOutput> <_TemplateOutputGroupOutput Include="@(_ZipItem->'%(ZipFile)')" > <TemplateSubPath>%(_ZipItem.Language)\%(_ZipItem.OutputSubPath)\%(_ZipItem.Culture)</TemplateSubPath> </_TemplateOutputGroupOutput> </ItemGroup> <ItemGroup> <TemplateOutputGroupOutput Include="@(_TemplateOutputGroupOutput->'%(FullPath)')" /> </ItemGroup> </Target>

    This uses _ZipProject.Language in the path. That definitely shows up in the output from the build of my Template project which is in bin\Debug\ProjectTemplates\CSharp\1033

    Finally my question: How do I stop the redundant Language folder appearing in the New Project dialogue?


  • Friday, February 01, 2013 8:59 PM
     
     
    Since my original question was answered (and this thread is marked as answered), you might be better off to open a new thread with your question and just reference this one.  If you do, link to your new thread from this one too so that others can find it :)

    - Dan - "Can't never could do anything"

  • Saturday, February 02, 2013 10:26 AM
     
     Proposed Has Code

    I have found a work around using post build on the template project and the file based mechanism in the VSIX project as apposed to the project reference.

    There is a possibility that this problem arises  because I am having to target both VS2010 and VS2012 with my VSIX. The source solution is all under VS2012, thus I am having to use vsixmanifest version 1.0 rather than 2.

    Basic work around.

    Put a post build step that copies the output .zip file from the "project template project" into the appropriate folder under ProjectTemplates in the VSIX project. e.g.

    copy "$(TargetDir)ProjectTemplates\CSharp\1033\*.zip" ..\..\..\FlowDevVSIX\ProjectTemplates\Assurity

    Make sure both the folder structure and the project template zip files are added to the VSIX project. It will look a bit like this.


    In the file properties for each .zip file, Set the "Build Action" to "Content" and  "Include in VSIX" to true.

    The folder structure below ProjectTemplates represents the Category structure you will see in the "New Project" dialog in VS.

    This line in the <Content> tag of the vsixmanifest file with then make your project templates appear in the same folder structure within the vsix and thus the new project dialog of VS.

    <ProjectTemplate>ProjectTemplates</ProjectTemplate>
    I'd love to find a way of sorting this without the post build step but project pressure means that I must move one. I've documented this work around here for anyone who finds they are suffering from the same problem as although this thread is effectively closed (answered) it does pop up in a web search.

    • Proposed As Answer by Elad Shaham Thursday, May 16, 2013 7:11 AM
    •