我正在开发Visual Studio的扩展,目标是允许用户通过TreeView选择类,然后单击“确定”按钮后,将使用选定的类生成项目。 这些类是通过反射来自特定文件夹中的程序集的方式加载的。 因此,我可以加载程序集,并通过TreeView用户可以选择所需的类。 关键是如何将这些类放入集合中,并在生成的项目模板中创建文件夹结构和类。有没有人建议如何做?
我的解决方案有2个项目:一个向导和一个模板:
我的向导实现:
using EnvDTE;
using Microsoft.VisualStudio.TemplateWizard;
using Primavera.Extensibility.Wizard.UI;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Primavera.Extensibility.Wizard
{
public class WizardImplementation : IWizard
{
private Modules frm;
// This method is called before opening any item that
// has the OpenInEditor attribute.
public void BeforeOpeningFile(ProjectItem projectItem)
{
}
public void ProjectFinishedGenerating(Project project)
{
}
// This method is only called for item templates,
// not for project templates.
public void ProjectItemFinishedGenerating(ProjectItem
projectItem)
{
}
// This method is called after the project is created.
public void RunFinished()
{
}
public void RunStarted(object automationObject,
Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
try
{
// Display a form to the user. The form collects the classes checked
frm = new Modules();
frm.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
// This method is only called for item templates,
// not for project templates.
public bool ShouldAddProjectItem(string filePath)
{
return true;
}
}
}