テンプレートへの参照を追加できるはずです。これは、[ファイル]->[追加]ウィンドウIWizard
をクリックすると実行されます。アセンブリとタイプをvstemplateファイルokに追加する必要があります。
RunFinished
または、場合によってはProjectItemFinishedGenerating
メソッドを実装します。次に、EnvDTE
Visual Studioによって公開されたオブジェクトを使用して、標準のVisualStudioExtensibilityモデルを使用してソリューション内の任意のアイテムを操作できます。
次のコードスニピット(オープンソースのT4 Toolboxから)は、このプロパティを設定する方法を示しています。
/// <summary>
/// Sets the known properties for the <see cref="ProjectItem"/> to be added to solution.
/// </summary>
/// <param name="projectItem">
/// A <see cref="ProjectItem"/> that represents the generated item in the solution.
/// </param>
/// <param name="output">
/// An <see cref="OutputFile"/> that holds metadata about the <see cref="ProjectItem"/> to be added to the solution.
/// </param>
private static void SetProjectItemProperties(ProjectItem projectItem, OutputFile output)
{
// Set "Build Action" property
if (!string.IsNullOrEmpty(output.BuildAction))
{
ICollection<string> buildActions = GetAvailableBuildActions(projectItem);
if (!buildActions.Contains(output.BuildAction))
{
throw new TransformationException(
string.Format(CultureInfo.CurrentCulture, "Build Action {0} is not supported for {1}", output.BuildAction, projectItem.Name));
}
SetPropertyValue(projectItem, "ItemType", output.BuildAction);
}
// Set "Copy to Output Directory" property
if (output.CopyToOutputDirectory != default(CopyToOutputDirectory))
{
SetPropertyValue(projectItem, "CopyToOutputDirectory", (int)output.CopyToOutputDirectory);
}
// Set "Custom Tool" property
if (!string.IsNullOrEmpty(output.CustomTool))
{
SetPropertyValue(projectItem, "CustomTool", output.CustomTool);
}
// Set "Custom Tool Namespace" property
if (!string.IsNullOrEmpty(output.CustomToolNamespace))
{
SetPropertyValue(projectItem, "CustomToolNamespace", output.CustomToolNamespace);
}
}