3

Is it possible to add a solution folders with the project template? If it's not built in functionality, is it possible to create a custom task for this?

marcus
  • 9,616
  • 9
  • 58
  • 108

5 Answers5

2

This is bit tricky. You cannot do this with simple project template. Project templates could operate only on single project level. To implement more advanced logic, you need to implement WizardExtension and register it within .vstemplate file of your template.

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

You can find more about wizard extensions on MSDN.

Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
1

You can do it using template wizards. I guess that you already know how to implement it.

So, inside RunFinished method, write these lines:

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

For Solution2 class you have to reference EnvDTE80.dll. _dte must be set from RunStarted method.

private DTE _dte;
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
     _dte = (DTE)automationObject;
}
hakan
  • 3,284
  • 2
  • 19
  • 25
1

It is possible, for how to you can check this msdn website. Or for the total overview

Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
Rick Hoving
  • 3,585
  • 3
  • 29
  • 49
0

Just simply add <SolutionFolder>...</SolutionFolder> in the .vstemplate file

<SolutionFolder Name="Math Classes">
        <ProjectTemplateLink ProjectName="MyFolder1">
            3rdpartyProj\MyTemplate.vstemplate
        </ProjectTemplateLink>
        <ProjectTemplateLink ProjectName="MyFolder2">
            3rdpartyProj\MyTemplate.vstemplate
        </ProjectTemplateLink>
    </SolutionFolder>

References: SolutionFolder

-3

I'm using the following snippets in my Project Template Wizard (see Mike Chaliy's answer):

        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;
    }

where_solution = (Solution2) _dte.Solution;

ulu
  • 5,872
  • 4
  • 42
  • 51
  • Ok, do you mind posting your complete IWizard implementation? I don't understand where I should call the GetSolutionFolder method? – marcus Mar 16 '12 at 14:29
  • public void RunStarted(object application, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) { _dte = application as _DTE; _solution = (Solution2) _dte.Solution; _solutionFolder = GetSolutionFolder(_solution); } – ulu Mar 17 '12 at 05:30