I'm trying to create my own class template for Visual Studio called "Public Class".
I followed the official MSDN instructions on how to manually create an Item Template pretty much to the letter, but I'm having no luck getting the template to show up in the "My Templates" section of the "Add New Item" dialog.
I placed PublicClass.zip in the following Windows XP directory:
C:\Documents and Settings\My User Name\My Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#.
Public Class.zip contains the following files:
- PublicClass.cs
- PublicClass.ico
- PublicClass.vstemplate
PublicClass.cs contains...
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;
namespace Pse.$projectname$
{
public class $safeitemname$
{
}
}
PublicClass.vstemplate contains...
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate
Type="Item"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>Public Class</Name>
<Description>An empty class declaration with access modifier = public and namespace = Pse.NameOfProject</Description>
<Icon>PublicClass.ico</Icon>
<ProjectType>CSharp</ProjectType>
<DefaultName>PublicClass.cs</DefaultName>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true">PublicClass.cs</ProjectItem>
</TemplateContent>
</VSTemplate>
I started up Studio, tried to add a new item to my project, but my template was nowhere to be found. So, I followed the advice of this stackoverflow question, which was to call...
devenv.exe /installvstemplates
...from the command line, but all that did was make all the templates (including the built-in ones) disappear. After a few moments of panic, I eventually got them back after running the command several times, but that clearly wasn't the answer for me.
If you see anything wrong with my procedure here, can you please help me out?
Thanks in advance.
EDIT:
If I use File/Export Template (as suggested by Preet), the template does show up in My Templates, but the parameters are not replacing properly.
If I insert a new "Public Class", this is what I get:
using System;
using System.Collections.Generic;
$if$ (3.5 == 3.5)using System.Linq;
$endif$using System.Text;
namespace Pse.$projectname$
{
public class PublicClass1
{
}
}
So, only $projectname$
and $targetframeworkversion$
are replacing properly. It's not handling the $if$
statement or $projectname$
properly. (I also tried using $safeprojectname$
, but that made no difference.)
This is definitely one of those cases where trying to make my life a little more convenient had had exactly the opposite effect :)