Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > 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"

Answers

  • 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.

  • 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
    •  

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 Answer

    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