c# - 如何将用户在向导中检查的类添加到项目模板?
问题描述
我正在为 Visual Studio 开发一个扩展,目标是允许用户通过 TreeView 选择类,并在单击 Ok 按钮后使用选定的类生成项目。这些类通过反射从特定文件夹中的程序集加载。所以我可以加载程序集并通过 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;
}
}
}
解决方案
推荐阅读
- html - 右侧的额外空间
- git - 强制推送到不同的分支时,Git 不会将新文件推送到远程
- sml - 在 SML 中将 int 转换为 real
- sql - 使用动态列名 SQL Server 连接
- c - ~(char)((unsigned char) ~0 >> 1) 到底发生了什么?
- javascript - 是否可以使用 ajax 执行任何 php 函数
- c# - 登录到第二个表单后如何传递名称变量
- javascript - 标签内容文件图像预览脚本不起作用
- html - Django - 一个 href 重复目标
- docker - 应用程序依赖于为环境变量采购 secrets.sh。如何在我的 Dockerfile 中实现这一点?