您应该能够添加IWizard
对模板的引用,这将在您单击ok“文件”->“添加”窗口时运行。您需要将程序集和类型添加到 vstemplate 文件中。
实施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);
}
}