Adding an folder to a multiple project Visual Studio 2010 Template - visual-studio-2010

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?

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

VC++ custom item template doesn't show up

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

Visual Studio 2010 Make and Install Templates

I am using F# and i found that the available templates were a bit to sparse for my liking, and i want to make more. How would i go about doing that? also, how would i install these templates after I've made them?
In Visual Studio's path you will find the default templates, these are a set of zip files that get expanded into the template cach.
They are stored in
Item Templates - %VSInstallDir%\Common7\IDE\ItemTemplates\
Project Templates - %VSInstallDir%\Common7\IDE\ProjectTemplates\
Extracting the {{.zip}} in question and recompressing with the modified contents will update the template. You can also copy these files to one of the respective template folders in %USERPROFILE%\Documents\Visual Studio 2010.
For information on building templates have a look at Visual Studio Templates on MSDN.
You then need to tell VS to rebuild the cache.
Open a visual studio command line shell
Execute devenv /installvstemplates
You can also use the "Export Template..." wizard from the file menu, however the exported template loses original content such as if statements.
I ran into problems with this and multiple custom templates. Each template (e.g. vstemplate + cs file) should be in it's own zip file. If you put several into the same zip it won't pick up any of them.
I also found that if you put them in:
$My Documents$\Visual Studio 2010\Templates\ItemTemplates
then you wont need run the command (devenv /installvstemplates) mentioned by Brett. Presumably this is only when modifying the existing ones in the install folder.
Here's a sample that I use for knocking up NUnit tests:
Code file (with .cs/relevant extension):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace $rootnamespace$
{
[TestFixture, Category("issue")]
public class $safeitemname$
{
[SetUp]
public void Setup()
{
}
[Test]
public void Test()
{
}
}
}
Template file (with .vstemplate extension):
<VSTemplate Version="3.0.0" Type="Item"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" >
<TemplateData>
<DefaultName>ATest.cs</DefaultName>
<Name>NUnit test</Name>
<Description>
with [TestFixture] attribute set on class and one empty method
called Test that has [Test] attribute
</Description>
<ProjectType>CSharp</ProjectType>
<SortOrder>10</SortOrder>
<Icon>someIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<References />
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs"
ReplaceParameters="true">TheCodeFile.cs</ProjectItem>
</TemplateContent>
</VSTemplate>
I'd try http://msdn.microsoft.com/en-us/library/ms185291.aspx - it seems like a good starting point, at least.
I was missing SharePoint 2010 and MOSS 2007 templates in Visual Studio 2010 development tool after my SharePoint installation. I reinstalled VS and found they were available. It looks like during installation of SharePoint pre-requisites for some reason I missed those templates from getting installed.
You can get the complete example implemented here: Multi-Project Templates with Wizard: Visual Studio 2010 Sample
You can download and install VS 2010 SDK (or VS 2010 SP1 SDK) which contains new project templates such as Item Template template and Project Template template (I don't know if there's version for earlier versions of VS and if these templates are only for C# or not).
Visual Studio 2010 SP1 SDK:
http://www.microsoft.com/download/en/details.aspx?id=21835
Visual Studio 2010 SDK:
http://www.microsoft.com/download/en/details.aspx?id=2680

Resources