You should be able to add an IWizard reference to the template, this will run when you click ok in the File -> Add window. You'll need to add the assembly and type to the vstemplate file.
实施RunFinished或者可能是ProjectItemFinishedGenerating方法。然后您可以使用EnvDTE
Visual Studio 公开的对象,用于使用标准 Visual Studio 可扩展性模型操作解决方案中的任何项目。
下面的代码片段(来自开源 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);
}
}