【发布时间】:2015-07-23 23:13:41
【问题描述】:
我创建了一个代码 sn-p(希望是第一个),主要使用 this article 作为指导。
这似乎奏效了。以下是我采取的步骤:
首先,我使用代码 sn-p (HtmlTableRowWithTwoCells.sn-p) 创建了这个文件:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/CodeSnippet">
<CodeSnippet Format="1.0.0">
<!-- The Title of the snippet, this will be shown in the snippets manager. -->
<Title>Create a 2-Cell HTML Table Row</Title>
<!-- The description of the snippet. -->
<Description>Creates a 2-Cell Row to be added to an HtmlTable</Description>
<!-- The author of the snippet. -->
<Author>Warble P. McGorkle for Platypi R Us (Duckbills Unlimited)</Author>
<!-- The set of characters that must be keyed in to insert the snippet. -->
<Shortcut>row2</Shortcut>
<!-- The set of snippet types we're dealing with - either Expansion or -->
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<!-- Now we have the snippet itself. -->
<Snippet>
<Declarations>
<Literal>
<ID>RowName</ID>
<ToolTip>Enter the Row instance name</ToolTip>
<Default>RowName</Default>
</Literal>
<Literal>
<ID>Cell1Name</ID>
<ToolTip>Enter the name for Cell 1</ToolTip>
<Default>Cell1Name</Default>
</Literal>
<Literal>
<ID>Cell2Name</ID>
<ToolTip>Enter the name for Cell 2</ToolTip>
<Default>Cell2Name</Default>
</Literal>
</Declarations>
<!-- Sepecify the code language and the actual snippet content. -->
<Code Language="CSharp" Kind="any">
<![CDATA[
var $RowName$ = new HtmlTableRow();
var $Cell1Name$ = new HtmlTableCell();
var $Cell2Name$ = new HtmlTableCell();
$RowName$.Cells.Add($Cell1Name$);
$RowName$.Cells.Add($Cell2Name$);
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
然后,我创建了这个“清单”文件(.vscontent):
<?xml version="1.0" encoding="utf-8" ?>
<VSContent xmlns="http://schemas.microsoft.com/developer/vscontent/2005" >
<Content>
<FileName>HtmlTableRowWithTwoCells.snippet</FileName>
<DisplayName>Inserts a 2-Cell HTML Table Row</DisplayName>
<Description>Inserts a 2-Cell Row to be added to an HtmlTable</Description>
<FileContentType>Code Snippet</FileContentType>
<ContentVersion>2.0</ContentVersion>
<Attributes>
<Attribute name="lang" value="csharp"/>
</Attributes>
</Content>
</VSContent>
我将这两个文件压缩在一起,将扩展名从 .zip 重命名为 .vsi,双击它,然后通过以下步骤将其安装到此处的“我的代码片段”文件夹中:
并且它表明sn-p 被安装在一个合理的位置:
然而,当我尝试在 VS 中添加代码片段时,我看到的唯一类别是这些(没有“我的代码片段”):
当我选择工具 > 代码片段管理器...时,我可以导航到 Visual C# > 我的代码片段,但它是空的。
当我使用代码片段管理器的“导入”按钮并导航到 sn-p 的位置并尝试添加 sn-p 文件时,我得到,“选择的 sn-p 文件无效.”
为什么它告诉我它安装成功,而它显然没有安装(或者它藏在哪里)?我忽略了哪个燃烧的箍让自己通过了?
“清单”文件的“奇怪”名称可能是问题所在吗? “.vscontent”对我来说似乎很奇怪,但这就是上面引用的文章所说的命名它。也许这只是疏忽,它真的应该是 [sn-pName].vscontent?
更新
显然,将“清单”文件命名为 *.vscontent” 不是问题。可能是 a 问题,但不是 问题,因为我将其命名为与 .sn-ps 文件相同(扩展名除外),再次进行了安装过程,并得到了完全相同的结果:表面上成功,实际士气低落。
btw,默认情况下,在选择要放置SN-P的类别时,代码Snipeets Manager将在“Microsoft Visual Studio工具”中的“应用程序2005> 2005>”代码片段“中进行复选框。我之前取消勾选并勾选了最上面的“我的代码片段”;这次我保留了默认选择,加上我的首选位置/类别加上“Visual C#”
但是,唉,在 VS 中似乎通过 Ctrl+K、X 显示的唯一类别是 C#,并且预期的快捷方式(“row2”)不会出现在 sn-p 下拉列表中。
【问题讨论】:
标签: visual-studio-2010 visual-studio code-snippets vsinstaller