VS2010 MPF: "Add-> New item ..." list for custom project
I created a special language pack that extends ProjectPackage. I can create a new project correctly. I would like to be able to add new source files to the project using the menu item Add-> New Item ... (Ctrl + Shift + A). However, when I click on this, the list of available templates is empty. I would like to add my own template in the menu of available templates for this type of project. Is there any documentation for this? The only mentions I saw were freezes in the registry, but there should be a way of programming programmatically, I think.
Is there any specific method that I can override to populate the list? I really need to create a template, or I can just show the "template name", "icon" and provide the correct file extension (when creating it, the files should be empty, so I think that the template is largely wasted on what I want to do )
This is the path that I have reached so far. I decided that I could set the project type and GUID in my .vproj file (.vproj is the file extension registered in my user project). I thought I could quickly create an element template with the same ProjectType as my .vproj file.
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item"> <TemplateData> <Icon>VerilogSource.ico</Icon> <DefaultName>module.v</DefaultName> <Name>Basic Verilog Module</Name> <Description> A basic Verilog module for quickly adding new files to the project. </Description> <ProjectType>VerilogProject</ProjectType> </TemplateData> <TemplateContent> <ProjectItem TargetFileName="$fileinputname$.v" ReplaceParameters="true">module.v</ProjectItem> </TemplateContent> </VSTemplate> Alas, this template does not appear at all, although I included it in VSIX and copied it to the output directory. If I placed this template in the same folder as my .vproj, it will appear as a template for creating a new project (not so!) And still will not appear in the list of my new elements. All this may be due to the fact that I do not use VSTemplate to create my project. Instead, I use [ProvideProjectFactoryAttribute] so that VS2010 knows where my vproj file is, and it will use the vproj file (which I think you could name a template, but it's not a VSTemplate, it's a project) to base a new design.
Here I am still, and I continue to try new things. I hope someone can have the answer I'm looking for. Thanks,
Giawa
After much reading and work, here is my answer:
Use vstemplate files for your project and elements and compile them as vstemplate (do not copy to output, do not include in VSIX, contrary to what Microsoft walkthrough does). The compiler will pack each element and project template into its own zip file. Now you need to tell vsixmanifest where these files are. The default directories for projects and items are ProjectTemplates and ItemTemplates, respectively. Add them to your vsixmanifest as follows:
<Content> <VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage> <ProjectTemplate>ProjectTemplates</ProjectTemplate> <ItemTemplate>ItemTemplates</ItemTemplate> </Content> Now you should also add some properties to your .csproj file into which your vsix package is embedded. These properties can probably be added using some confusing method, but the easiest way is to simply remove them directly in the .csproj file.
<PropertyGroup> <GetVsixSourceItemsDependsOn>$(GetVsixSourceItemsDependsOn);GetVsixTemplateItems</GetVsixSourceItemsDependsOn> </PropertyGroup> <Target Name="GetVsixTemplateItems" DependsOnTargets="ZipProjects;ZipItems"> <ItemGroup> <VSIXSourceItem Include="@(IntermediateZipItem)"> <VSIXSubPath>ItemTemplates\%(IntermediateZipItem.Language)\%(IntermediateZipItem.OutputSubPath)\%(IntermediateZipItem.Culture)</VSIXSubPath> </VSIXSourceItem> <VSIXSourceItem Include="@(IntermediateZipProject)"> <VSIXSubPath>ProjectTemplates\%(IntermediateZipProject.Language)\%(IntermediateZipProject.OutputSubPath)\%(IntermediateZipProject.Culture)</VSIXSubPath> </VSIXSourceItem> </ItemGroup> </Target> Now you include your zip files in your project, and with some luck you will now have projects and elements that are correctly connected to each other.
Fortunately, quite a lot of documentation exists for element / project templates. It just took me a while to figure out that this is the right way. Good luck
Giawa
All these steps can be performed automatically in Visual Studio:
First create an element template in a separate project (you can do this using File > Export template ). You can customize this template by editing the .vstemplate file.
After you receive the .zip file, drag it into the main VSPackage solution and follow these steps:
- Click the
.vsixmanifestfile. - Click
Assets > New. - Set
TypetoMicrosoft.VisualStudio.ItemTemplate( Element Template ). - Set
SourcetoFile on filesystem. - Set
Pathto your.zipelement template template. - Recover the solution.
Note. I used Visual Studio 2013.