4.添加VSIX开发要用到的相关类库。在FirstProjectWizard项目下的引用鼠标右键,添加
EnvDTE、Microsoft.VisualStudio.TemplateWizardInterface、System.Drawing、System.Windows、System.Windows.Forms等。
5.在FirstProjectWizard项目中添加类,并命名为WizardImplementation,并继承IWizard接口,具体代码如下:
using EnvDTE; using Microsoft.VisualStudio.TemplateWizard; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace FirstProjectWizard { public class WizardImplementation : IWizard { private CustomFieldForm customFieldForm; private string customField; public void BeforeOpeningFile(ProjectItem projectItem) { } public void ProjectFinishedGenerating(Project project) { } public void ProjectItemFinishedGenerating(ProjectItem projectItem) { } public void RunFinished() { } public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { try { customFieldForm = new CustomFieldForm(); customFieldForm.ShowDialog(); customField = CustomFieldForm.CustomField; //添加自定义参数 replacementsDictionary.Add("customField", customField); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } public bool ShouldAddProjectItem(string filePath) { return true; } } }