I'm currently putting together a .vsix which contains various item and project templates using SideWaffle and TemplateBuilder v1.1.4.9-beta. When running the project in an experimental instance, I can see all of the project templates where they should be, but the item templates aren't available in the Add New Item dialog for any project types except Console Applications. The behaviour is the same if I compile the project to a release .vsix and install it for Visual Studio the traditional way.
Folder structure for one example template for reference:
The content of CSharp.vestemplate:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<ProjectType>CSharp</ProjectType>
<DefaultName>my_layout.xml</DefaultName>
<Name>My Layout</Name>
<Description>My Description</Description>
<Icon>icon.png</Icon>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<TemplateID>65197798-4682-45e6-9bf4-d2d9e2929527</TemplateID>
<SortOrder>1000</SortOrder>
</TemplateData>
<TemplateContent>
<References />
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.xml">my_layout.xml</ProjectItem>
</TemplateContent>
</VSTemplate>
I've already tried:
Setting values for ShowByDefault, ProjectSubType, and TemplateGroupID in the .vstemplate
Fiddling with the folder structure
Comparing my .csproj and .vsixmanifest files line-by-line with those of other template packs, like SideWaffle
but all to no avail so far.
Despite Microsoft's documentation lacking any reference to them, the TemplateGroupId types MonoAndroid and Xamarin.iOS are available, and must be specified within the template's .vstemplate. Adding the following element to a TemplateData element gets the template to show up correctly:
<TemplateGroupID>MonoAndroid</TemplateGroupID>
It's fairly frustrating that the available TemplateIDs don't seem to be properly documented anywhere, and the ones that do work follow seemingly random naming conventions (one would expect MonoAndroid and MonoTouch, or Xamarin.Android and Xamarin.iOS, but instead only MonoAndroid and Xamarin.iOS actually work...).
Related
I have tried to create a custom project template for Visual Studio Community 2017 for c++. I have exported the project as a template, however when I try to access the files I added in a new project, they are not created in the project folder. I can try to open them in the Solution Explorer, but the files themselves are not being created. I have tried to add <CreateinPlace>true</CreateInPlace> as well as adding the .zip files to the VS template directory, but these had no effect. How would I be able to add the files to the template and get them to show up in a new project?
What it actually was is that the .vstemplate wasn't adding the files as project items, so when I exported the project, it didn't know to look for them.
To fix it I just added
<TemplateContent>
<Project TargetFileName="CS235-Template.vcxproj" File="CS235-Template.vcxproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.vcxproj.filters">CS235-Template.vcxproj.filters</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="main.cpp">main.cpp</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Debug.h">Debug.h</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="input.txt">input.txt</ProjectItem>
</Project>
</TemplateContent>
After doing this they worked just fine.
Visual Studio stores the template in 3 different locations. The folder that VS tells you is only one of the 3 options. I finally modified the .vstemplate file in:
Libraries\Documents\Visual Studio 2017\Templates\ProjectTemplates
Unzip the file (Right-Click->Extract All)
Open the .vstemplate file
Add <CreateInPlace>true</CreateInPlace> to the <TemplateData> section
Save the file
Rezip the file (or don't. It works either way but if you leave the zip file the template will show up twice)
The following answer is a little off topic but it's the one that helped me solve the problem.
[Answer][https://stackoverflow.com/a/48274550/4892466]
I'm creating a VS 2013 project template and one of the file types you can add to it is an XML file which I have the XSD for but I've been unable to figure out how to tell VS that when the file is added, assign the schema to it.
I Have something like this. Assume the the schema is Format.XSD, i've poked around the projectitem schema but couldnt find anything related.
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<DefaultName>type.format.ps1xml</DefaultName>
<Name>PowerShell Format File</Name>
<Description>An type format definition</Description>
<ProjectType>PowerShell</ProjectType>
<SortOrder>10</SortOrder>
<Icon>PowerShell.ico</Icon>
</TemplateData>
<TemplateContent>
<References>
</References>
<ProjectItem TargetFileName="$fileinputname$.format.ps1xml" ReplaceParameters="false">format.ps1xml</ProjectItem>
</TemplateContent>
</VSTemplate>
An old question but here's an answer just for the records. It might help others.
So unfortunately the VSTemplate schema doesn't allow you to specify an XSD for your XML file.
To do the trick, you have to add files to the Visual Studio Schema Cache.
The Schema Cache is a folder here: %visual-studio-directory%\Xml\Schemas
Add your XSD file.
Add an XML file (so called catalog file) that associates your file extension with your XSD. (The name of the catalog file can be anything but its extension must be .xml)
Eg.
<?xml version="1.0" encoding="utf-8"?>
<SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
<Association extension="myextension" schema="%InstallRoot%/xml/schemas/MyXsd.xsd" />
</SchemaCatalog>
UPDATE:
Starting with Visual Studio 2017 you can use VSIX (Visual Studio Extensibility) to install XSD files to the Visual Studio Schema folder.
See: https://learn.microsoft.com/en-us/visualstudio/extensibility/set-install-root
I tried making an item template. In the zip I put the files module.cpp, module.h, module.ico and module.vstemplate. The vstemplate file is:
<VSTemplate Type="Item" Version="2.0.0"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>C++ cpp/h pair (st)</Name>
<Description></Description>
<Icon>module.ico</Icon>
<ProjectType>VisualC</ProjectType>
<DefaultName>MyClass</DefaultName>
</TemplateData>
<TemplateContent>
<ProjectItem TargetFileName="$fileinputname$.cpp">module.cpp</ProjectItem>
<ProjectItem TargetFileName="$fileinputname$.h">module.h</ProjectItem>
</TemplateContent>
</VSTemplate>
I copied this to the "custom item templates" dir (not the systemwide one): Documents\Visual Studio 2010\Templates\ItemTemplates\VisualC\module.zip
The VisualC folder wasn't there, I created it because I saw one called VisualC in the systemwide templates dir.
I've tried restarting VS. I also tried the "devenv /installvstemplates" thing just in case.
There is a small note on ItemTemplates page on MSDN:
You cannot export templates for C++ projects.
Fortunately there is a solution, but much more complex than you expect.
Search MSDN for Visual C++ Wizards (sorry reputation too low to paste more links).
Starting point could be:
http://msdn.microsoft.com/en-us/library/vstudio/96xz4cw2(v=vs.100).aspx
http://msdn.microsoft.com/en-us/library/aa730846(VS.80).aspx
I've been working on a full vertical stack template for Visual Studio (It's on Github if you'd like to help out: https://github.com/Adron/infrastructure
My problem is, I have not been able to add a folder for assemblies in the root of the solution. The individual project templates (which I have three in the overall parent solution template) have many individual elements, such as files and folders. But when I try to add anything like that to the parent template it reports that it is not valid in this XML schema/file.
My current solution XML file looks like this:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
<TemplateData>
<Name>ASP.NET MVC 3 + Razor + Machine.Specifications Infrastructure Solution</Name>
<Description>This Visual Studio Template provides the following pieces for getting a kick start when building well designed web sites using good patterns.</Description>
<EnableEditOfLocationField>true</EnableEditOfLocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<ProvideDefaultName>true</ProvideDefaultName>
<Icon>Icon.ico</Icon>
<ProjectType>CSharp</ProjectType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>Infrastructure</DefaultName>
<LocationField>Enabled</LocationField>
<PreviewImage>Preview.png</PreviewImage>
</TemplateData>
<TemplateContent>
<ProjectCollection>
<ProjectTemplateLink ProjectName="Infrastructure.Web">Web\MyTemplate.vstemplate</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="Infrastructure.Specifications">Specifications\MyTemplate.vstemplate</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="Infrastructure.Data">Data\MyTemplate.vstemplate</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
Any ideas on how to add folders or individual assets? Thanks...
Here's part of my solution that includes Solution Items:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8C6F0281-2022-4F98-A856-590C5FE26BC1}"
ProjectSection(SolutionItems) = preProject
..\Build.bat = ..\Build.bat
..\Build.proj = ..\Build.proj
..\ClickToBuild.bat = ..\ClickToBuild.bat
..\DeployStage.bat = ..\DeployStage.bat
LocalTestRun.testrunconfig = LocalTestRun.testrunconfig
Performance1.psess = Performance1.psess
EndProjectSection
EndProject
Does that help any?
I've got a project template which I want to appear under both "Visual C#" and its subtype "Test". I can get it to appear in one but not the other by placing it in
\Visual Studio 2008\Templates\ProjectTemplates\Visual C#
and
\Visual Studio 2008\Templates\ProjectTemplates\Visual C#\Test
respectively.
I've tried setting the following attributes in the vstemplate file
<ProjectType>CSharp</ProjectType>
<ProjectSubType>Test</ProjectSubType>
But it doesn't seem to work.
I've also looked at the default templates for ideas but can't find anything.
Is there a way of doing this without putting a copy in both locations?
Just found the NumberOfParentCategoriesToRollUp tag. By saying
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
It puts it in the parent as well (the template goes in the Test folder). The description claims it doesn't work for user templates but it works for me.