VS documentation says AddFromTemplate will return null for C# and VB project. I have no clue why, but it's true. Therefor the output of the action will be null for some projects
Here's a workaround (a custom action that does the same, but then finds/sets the output explicitly):
using
System;
using
System.Collections.Generic;
using
System.Text;
using
Microsoft.Practices.ServiceFactory.Actions;
using
Microsoft.Practices.RecipeFramework;
using
Microsoft.Practices.RecipeFramework.Extensions.Actions.VisualStudio;
using
EnvDTE;
using
Microsoft.Practices.RecipeFramework.Extensions.Actions.Templates;
using
System.IO;
using
Microsoft.Practices.Common.Services;
using
System.ComponentModel.Design;
using
System.Diagnostics;
using
Microsoft.VisualStudio.Shell.Interop;
using
EnvDTE80;
namespace
Microsoft.Practices.ServiceFactory.Actions.CreateProject {
public class CreateProjectAction : ActionBase {
private string projectName;
[Input(Required = true)]
public string ProjectName {
get { return projectName; }
set { projectName = value; }
}
private string template;
[Input(Required = true)]
public string Template {
get { return template; }
set { template = value; }
}
private string projectFolder;
[Input(Required = true)]
public string ProjectFolder {
get { return projectFolder; }
set { projectFolder = value; }
}
private EnvDTE.Project project;
[Output()]
public EnvDTE.Project Project {
get { return project; }
set { project = value; }
}
public override void Execute() {
EnvDTE.
DTE dte = this.GetService<EnvDTE.DTE>(true);
Solution2 soln = (Solution2)dte.Solution;
project = soln.AddFromTemplate(template, projectFolder, projectName,
false);
//AddFromTemplate returns null for C# projects !!!
foreach (Project p in soln.Projects) {
if (p.Name == projectName)
this.project = p;
}
}
public override void Undo() {
//Do Nothing
}
}
}