Today a friend of mine had a problem with the method AddFromTemplate, I don't know why but the method returns always null.
While I was trying to help him I create a guidance solution and create a action and in that action I try create a project and add that project to the solution using the method AddFromTemplate.
So what I did try was:
public override void Execute()
{
DTE dte = (DTE)GetService(typeof(DTE));
Project project = dte.Solution.AddFromTemplate(@"D:\Demo\GuidancePackage1\GuidancePackage1\Templates\Projects\ClientApplicationTest\ClientApplication.vstemplate", @"D:\Demo\GuidancePackage1Solution2\Project", "NovoProjecto", false);
}
but this gives me an error saying "Template Configuration is missing or invalid" what a nice error it doesn't help much. After looking a while I found the problem and it has nothing to do with that message.
The problem was that I used a .vstemplate file that has the element
<WizardExtension>
<Assembly>Microsoft.Practices.RecipeFramework.VisualStudio, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate</FullClassName>
</WizardExtension>
This element is needed when I need to run a recipe during unfold template. Since I don't need to run a recipe and since I can't run a recipe inside another recipe, that was my problem.
The other problem wasn't solved. I don't know why AddFromTemplate returns null even when the project is created. So the solution was after create the project do a search using method DteHelper.FindProject to find the project.