我试图为Visual Studio创建我自己的类模板,名为“公共类”。我的Visual Studio 2008模板有什么问题?
我跟着the official MSDN instructions on how to manually create an Item Template很接近这封信,但我没有运气让模板显示在“添加新项”对话框的“我的模板”部分。
我把PublicClass.zip在下列Windows XP的目录:
C:\ Documents和Settings \我的用户名\我的文档\ Visual Studio 2008的\模板\的ItemTemplate \ Visual C#中。
公共Class.zip包含以下文件:
- PublicClass.cs
- PublicClass.ico
- PublicClass.vstemplate
PublicClass.cs包含...
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包含...
<?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>
我开始了工作室,尝试新的项目添加到我的项目,但我的模板是无处可寻。于是,我跟着的this stackoverflow question命令行的建议,这是叫......
devenv.exe /installvstemplates
...,但这一切所做的是让所有的模板(包括内置的)消失。经过一段时间的恐慌之后,我最终在多次执行命令后将它们还给了他们,但这显然不是我的答案。
如果您在这里看到我的程序有任何问题,您能否帮我解决问题?
在此先感谢。
编辑:
如果我使用的文件/导出模板(由普里特的建议),模板不在我的模板显示出来,但参数不正确地更换。
如果我插入一个新的“公共课堂”,这是我得到:
using System;
using System.Collections.Generic;
$if$ (3.5 == 3.5)using System.Linq;
$endif$using System.Text;
namespace Pse.$projectname$
{
public class PublicClass1
{
}
}
因此,只有$projectname$
和$targetframeworkversion$
正确更换。它没有正确处理$if$
声明或$projectname$
。 (我也尝试使用$safeprojectname$
,但是这并没有区别。)
这绝对是那些情况下,试图让我的生活更方便一点一人正好有相反的效果:)
你正在关闭VS不是吗? – 2009-08-03 01:58:05
是的。我试着将zip文件移动到不同的文件夹位置。我在工具...验证目录设置正确的选项。 – devuxer 2009-08-03 02:52:27