VC++ custom item template doesn't show up - visual-studio-2010

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

Related

Visual studio 2017 Community project template

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]

Visual Studio item templates only available for console applications

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

Project Item Template: xml file type with XSD/schema

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

How to force MSBuild to copy empty folders in project?

I have an MVC 4 project in Visual Studio 2012. There is Logs folder in it containing only four empty subfolders. This structure is needed by one library I use. I included these folders to project like this:
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="XSockets\XSocketServerPlugins\Log\XConnectionInterceptor\" />
<Folder Include="XSockets\XSocketServerPlugins\Log\XErrorInterceptor\" />
<Folder Include="XSockets\XSocketServerPlugins\Log\XHandshakeInterceptor\" />
<Folder Include="XSockets\XSocketServerPlugins\Log\XMessageInterceptor\" />
</ItemGroup>
But this is not enough and all these folders (including App_Data which was there from creation of project by Visual Studio) are not copied to package. Can I somehow force MSBuild to copy them even though they are empty?
Add a PostBuild step to copy the folders.
I can't answer specifically for VS2012, but here's how you do this in VS2010:
Right-click on the project and select Properties
Display the Build Events tab
Put your copy commands in the post-build event commands
If you click the edit button, the pop-up dialog will have a macros button that lists all of the available VS variables you can use to avoid using explicit paths, etc.
In VS2010, that modifies the project file to look something like this:
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)\*.*" "$(ProjectDir)\..\..\..\net40"</PostBuildEvent>
</PropertyGroup>
Do not edit the project file.
I can see that you are using an older version on XSockets, Right?
Do as Brenda says and do not mind the project file.
Look at the image attached...
Not 100% sure that it is this that you are looking for, but... it shows both pre- and post- build events
Regards
Uffe, Team XSockets

Adding an folder to a multiple project Visual Studio 2010 Template

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?

Resources