主にこの記事をガイダンスとして使用して、コード スニペットを作成しました (できれば最初のコードです) 。
うまくいったようです。私が取った手順は次のとおりです。
まず、コード スニペット (HtmlTableRowWithTwoCells.snippet) を使用してこのファイルを作成しました。
<?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>
これらの 2 つのファイルを一緒に圧縮し、拡張子を .zip から .vsi に名前を変更し、2 回クリックして、次の手順で "My Code Snippets" フォルダーにインストールしました。
また、スニペットが適切な場所にインストールされたことを示しています。
それでも、VS でコード スニペットを追加しようとすると、次のカテゴリのみが表示されます (「マイ コード スニペット」はありません)。
[ツール] > [コード スニペット マネージャー...] を選択すると、[Visual C#] > [マイ コード スニペット] に移動できますが、空です。
コード スニペット マネージャーの [インポート] ボタンを使用してスニペットの場所に移動し、スニペット ファイルを追加しようとすると、「選択されたスニペット ファイルが無効でした」というメッセージが表示されます。
明らかにインストールされていないのに (またはどこに隠れているのか)、インストールが成功したと表示されるのはなぜですか? 私が自分自身を飛び越えるのを怠ったのは、どの炎のフープですか?
「マニフェスト」ファイルの「奇妙な」名前が問題になる可能性はありますか? 「.vscontent」は私には奇妙に思えますが、上記の記事ではそのように命名されています。おそらくそれは単なる見落としであり、実際には [snippetName].vscontent である必要がありますか?
アップデート
どうやら、「マニフェスト」ファイルに *.vscontent という名前を付けることは問題ではありません。おそらく問題ではありますが、拡張子を除いて .snippets ファイルと同じ名前を付けたため、問題ではありません。もう一度処理して、まったく同じ結果が得られました。
ところで、デフォルトでは、スニペットを配置するカテゴリを選択すると、Code Snipeet Manager は「Microsoft Visual Studio Tools for Applications 2005 > My Code Snippets」にチェックボックスを入れます。以前はチェックを外し、一番上の「マイコードスニペット」にチェックを入れていました。今回は、デフォルトの選択を保持し、好みの場所/カテゴリと「Visual C#」を追加しました
しかし残念なことに、Ctrl + K、VS の X を介して表示される唯一のカテゴリは C# であり、予想されるショートカット ("row2") はスニペットのドロップダウンに表示されません。