2012-02-09 149 views

回答

2

這有點棘手。你不能用簡單的項目模板來做到這一點。項目模板只能在單個項目級別上運行。要實現更高級的邏輯,您需要實施WizardExtension並將其註冊到模板的.vstemplate文件中。

<WizardExtension> 
    <Assembly>AssemblyInGACWithSomeLogic</Assembly> 
    <FullClassName>MySuperWizardExtension</FullClassName> 
</WizardExtension> 

您可以在MSDN上找到更多關於嚮導擴展的信息。

-3

我用下面的代碼片段在我的項目模板嚮導(見麥克Chaliy的答案):

 private static SolutionFolder GetSolutionFolder(Solution2 solution) { 
     var project = GetSolutionFolderProject(solution); 
     return (SolutionFolder) project.Object; 
    } 

    private static Project GetSolutionFolderProject(Solution2 solution) { 
     var project = 
      solution.Projects.Cast<Project>().FirstOrDefault(p => p.Name == "Solution Items"); 
     if (project == null) project = solution.AddSolutionFolder("Solution Items"); 
     return project; 
    } 

其中_solution = (Solution2) _dte.Solution;

+0

好吧,你介意發佈你的完整的IWizard實現嗎?我不明白我應該在哪裏調用GetSolutionFolder方法? – Marcus 2012-03-16 14:29:39

+0

public void RunStarted(object application,Dictionary replacementsDictionary,WizardRunKind runKind,object [] customParams){ \t \t \t _dte = application as _DTE; \t \t \t _solution =(Solution2)_dte.Solution; \t \t \t _solutionFolder = GetSolutionFolder(_solution); \t \t} – ulu 2012-03-17 05:30:55

0

可以使用模板嚮導做。我想你已經知道如何實現它。

所以,RunFinished方法裏面,寫這幾行:

var destFolder = Directory.GetParent(path).Parent; 
    System.IO.Directory.CreateDirectory(destFolder.FullName + "\\.nuget"); 
    ((Solution2) _dte.Solution).AddSolutionFolder(destFolder.FullName + "\\.nuget"); 

對你有參考EnvDTE80.dll溶液2類。 _dte必須從RunStarted方法設置。

private DTE _dte; 
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) 
{ 
    _dte = (DTE)automationObject; 
} 
相關問題