Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > CreateProjectAction, TextTemplateAction and AddItemFromStringAction are not compatible in one recipe
 

CreateProjectAction, TextTemplateAction and AddItemFromStringAction are not compatible in one recipe

I was wondering if anyone else has seen this or has a suggestion for a solution.

I have aneed to create two projects when launching a single guidance automation recipe. Therefore, my intention was to create a recipe that would create one project, add some .cs files to it and then create the other project and add some .cs files to it.

I created the following actions to create the first assembly and add a .cs file to it.

<Action Name="CreateProject"

Type="Microsoft.Practices.RecipeFramework.Library.Actions.CreateProjectAction, Microsoft.Practices.RecipeFramework.Library">

<Input Name="ProjectName" RecipeArgument="ProjectName"/>

<Input Name="Template" RecipeArgument="ServerTemplate"/>

<Input Name ="ProjectFolder" RecipeArgument="ServerFolder"/>

<Output Name ="Project"></Output>

</Action>

<Action Name="GenerateComponentFile"

Type="Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TextTemplateAction, Microsoft.Practices.RecipeFramework.VisualStudio.Library"

Template="Projects\RemotableComponent\Server\Component.cs">

<Input Name="ComponentName" RecipeArgument="ComponentName" />

<Input Name="DefaultNamespace" RecipeArgument="DefaultNamespace" />

<Output Name="Content" />

</Action>

<Action Name="AddComponentFile"

Type="Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction, Microsoft.Practices.RecipeFramework.Library">

<Input Name="Content" ActionOutput="GenerateComponentFile.Content" />

<Input Name="TargetFileName" RecipeArgument="TargetFile" />

<Input Name="Project" ActionOutput="CreateProject.Project" />

</Action>

When I run the recipe, I receive the following error:

Microsoft.Practices.RecipeFramework.ActionExecutionException: An exception occurred during the binding of reference or execution of recipe ProjectRemotableComponentRecipe. Error was: Action AddComponentFile failed to execute:
Argument can not be null or have an empty value.
Parameter name: Project.
You can remove the reference to this recipe through the Guidance Package Manager. ---> System.ArgumentNullException: Argument can not be null or have an empty value.
Parameter name: Project
at Microsoft.Practices.RecipeFramework.Recipe.SetupInputs(IAction action, Action config, IDictionary actions, IDictionaryService arguments)
at ....

The project is created but .cs file is not added to the project. If I split the actions into seperate recipes (one to create the project, one to create the .cs file) it works fine. It appears to me that a recipe cannot have multiple output values which to work with, is this correct? If not, can anyone tell me why this will not work?

Thanks!

BJB

bjayb  Tuesday, December 04, 2007 6:12 PM

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

}

}

}

Michel Baladi  Wednesday, April 30, 2008 1:07 PM

As additional information, I discovered that the output value of Project from CreateProjectAction is null when completing the first action. This seems to be the general problem but I am not sure why, any thoughts would be appreciated.

Thanks!

bjayb  Tuesday, December 04, 2007 7:36 PM
Hi,
What kind of template are you trying to unfold? It's a webproject or just a c# project.?
Jose Escrich  Thursday, December 06, 2007 8:03 PM

Sorry for the delay in responding, I was having trouble posting a reply yesterday.

It is a simple C# project.

bjayb  Friday, December 07, 2007 6:40 PM
I will investigate why that is happening, but it seems a bug in the CreateProjectAction.
jose.
Jose Escrich  Wednesday, December 12, 2007 7:09 PM

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

}

}

}

Michel Baladi  Wednesday, April 30, 2008 1:07 PM

You can use google to search for other answers

Custom Search

More Threads

• Problem on installing GAT
• Web Service Software Factory (WCF) - cannot add service reference
• Can't able to run a recipe more than Once
• CommandBars
• How to add a template without opening it.
• How to make item templates appear in "sub categories" in VS 2008
• Refrence troubles
• Register Guidance Package Popup was not available on Microsoft Visual Studio 2008 Experimental hive.
• The Key combination (ctrl+R, ctrl+R) for word wrap not working
• Always publish release build