回答

2

好的......我已經嘗試了很多東西,但最後我結束了定製的IWizard。

public class InitScriptWizard : IWizard 
{ 
    public void RunStarted(
     object automationObject, 
     Dictionary<string, string> replacementsDictionary, 
     WizardRunKind runKind, 
     object[] customParams) 
    { } 

    public void ProjectFinishedGenerating(Project project) 
    { 
     var script = 
      project.ProjectItems.FindProjectItem(
       item => item.Name.Equals("init.ps1")); 

     if (script == null) 
     { 
      return; 
     } 

     var process = 
      System.Diagnostics.Process.Start(
       "powershell", 
       string.Concat(
        "-NoProfile -ExecutionPolicy Unrestricted -File \"", 
        script.FileNames[0], 
        "\"")); 

     //if (process != null) 
     //{ 
     // process.WaitForExit(); 
     //} 

     //script.Delete(); 
    } 

    public void ProjectItemFinishedGenerating(ProjectItem projectItem) 
    { } 

    public bool ShouldAddProjectItem(string filePath) 
    { 
     return true; 
    } 

    public void BeforeOpeningFile(ProjectItem projectItem) 
    { } 

    public void RunFinished() 
    { } 
} 
+0

This works。不要相信[MSDN](http://msdn.microsoft.com/zh-cn/library/ms185301.aspx).dll與您的嚮導只能部署到GAC。程序集可以未簽名並用VSIX部署,請檢查[本文](http://oncoding.blogspot.com/2012/04/visual-studio-template-wizards-without.html)(適用於我)。 – whyleee

+0

我有一個問題與var腳本= project.projectItems.FindProjectItem(item => item.Name.Equals(「init.ps1」)); 錯誤是ProjectItems不包含FindProjectItem的定義,並沒有擴展方法「FindProjectItem」接受的類型「ProjectItems」等第一參數......(是否缺少用戶指令或程序集引用) 任何幫助非常感謝。 – David

+0

這只是一個簡單的擴展方法。你可以在這裏看到:https://gist.github.com/philipproplesch/88540038e0d446c93769 – philipproplesch