C# 什么';我的VisualStudio2008模板有什么问题?
我正在尝试为VisualStudio创建自己的类模板,称为“公共类” 我基本上是照章办事,但是我没有运气让模板出现在“添加新项目”对话框的“我的模板”部分 我将PublicClass.zip放在以下Windows XP目录中: C:\Documents and Settings\My用户名\My Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C# Public Class.zip包含以下文件:C# 什么';我的VisualStudio2008模板有什么问题?,c#,visual-studio,templates,C#,Visual Studio,Templates,我正在尝试为VisualStudio创建自己的类模板,称为“公共类” 我基本上是照章办事,但是我没有运气让模板出现在“添加新项目”对话框的“我的模板”部分 我将PublicClass.zip放在以下Windows XP目录中: C:\Documents and Settings\My用户名\My Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C# Public Class.zip包含以下文件: 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$
{
}
}
<?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>
PublicClass.vstemplate包含…
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;
namespace Pse.$projectname$
{
public class $safeitemname$
{
}
}
<?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>
…从命令行,但所做的只是使所有模板(包括内置模板)消失。在几分钟的恐慌之后,我在运行了几次命令之后终于把它们弄回来了,但这显然不是我的答案
如果你发现我的程序有什么问题,你能帮我解决吗
提前谢谢
编辑:
如果我使用文件/导出模板(如Preet所建议的),模板确实会显示在我的模板中,但参数没有正确替换
如果我插入一个新的“公共类”,我得到的是:
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$
,但没有什么不同。)
这肯定是其中一种情况,试图让我的生活更方便一点却产生了完全相反的效果:)我对手动创建的ZIP文件有问题。除非我导出了一个现有的模板并对其进行了更改,否则我永远不会让该模板出现 我对手动创建的ZIP文件有问题。除非我导出了一个现有的模板并对其进行了更改,否则我永远不会让该模板出现 我遇到了这个问题:) 我想我成功地解决了这个问题,我做了一些非常类似的事情,我真正想要的是为我们的svn系统提供一个标准模板,其中包含了标题,我最终提取了Foo:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033中现有的Class.zip文件,然后编辑了它这个
// $Id$
// $Author$
namespace $rootnamespace$
{
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5) using System.Linq;
$endif$ using System.Text;
public class $safeitemrootname$
{
}
}
如果前面有制表符或空格,则$if$语句的间距似乎会有所不同。它们不会正确计算,或者说,它们确实会像您看到的那样计算,但只是打印在我的代码中
至于您的模板在运行/installvstemplates时消失,您可能会注意到cmd运行需要相当长的时间,实际上它所做的是删除
Foo:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache,然后通过提取上述原始位置中的zip文件来重建该文件夹。要使此命令正常运行,visual studio最好在运行时关闭,您应该等到命令完成后再重新启动它。(提示:我过去常常监视文件夹并观察它的构建)
就我个人而言,虽然这是一个灵活的系统,但微软真的可以让用户更轻松,毕竟R#有一个简单的右键单击功能,如果你有R#,这是在ms系统之外实现模板的最简单方法。我有这个问题:)
我想我成功地解决了这个问题,我做了一些非常类似的事情,我真正想要的是为我们的svn系统提供一个标准模板,其中包含了标题,我最终提取了Foo:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033中现有的Class.zip文件,然后编辑了它这个
// $Id$
// $Author$
namespace $rootnamespace$
{
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5) using System.Linq;
$endif$ using System.Text;
public class $safeitemrootname$
{
}
}
如果前面有制表符或空格,则$if$语句的间距似乎会有所不同。它们不会正确计算,或者说,它们确实会像您看到的那样计算,但只是打印在我的代码中
至于您的模板在运行/installvstemplates时消失,您可能会注意到cmd运行需要相当长的时间,实际上它所做的是删除
Foo:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache,然后通过提取上述原始位置中的zip文件来重建该文件夹。要使此命令正常运行,visual studio最好在运行时关闭,您应该等到命令完成后再重新启动它。(提示:我过去常常监视文件夹并观察它的构建)
就个人而言,虽然这是一个灵活的系统,但微软真的可以让用户更容易使用,毕竟R#有一个简单的右键点击功能,如果您有R#这是在ms系统之外实现模板的最简单方法。如果您希望它在Visual Studio 2008中工作,则必须在.vstemplate文件中将
更改为
。然后将.zip文件放在指定的用户项模板位置。如果希望它在Visual Studio 2008中工作,则必须将.vstemplate文件中的
更改为
。然后将.zip文件放在您指定的用户项目模板位置。您正在关闭VS,不是吗?是的。我还试着将zip文件移动到不同的文件夹位置。我在工具…选项中验证了目录设置正确。你正在关闭VS,是吗?是的。我还试着将zip文件移动到不同的文件夹位置。我在工具…选项中验证了目录设置是否正确。这样可以显示模板,但当我插入模板时,它无法正常工作。在自动生成的vstemplate文件中,ReplaceParameters肯定设置为true,但是$if$
sta