There are various posts on the forum that talk about this, but I haven'thad much luck getting anyof the answers to work. So, ifI want to call another action from the execute() method of another action, howdoI do this?Which host service(s) doI use, etc? This I what I'm currently doing:
DTE dte = GetService<DTE>();
using (Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction myAction = new Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction())
{
base.Container.Add(myAction);
myAction.Content = "Test";
myAction.TargetFileName = "test.txt";
// add it to a random project
foreach (Project p in dte.Solution.Projects)
{
myAction.Project = p;
}
System.Windows.Forms. MessageBox.Show("Added to project " + myAction.Project.Name);
}
Unfortunately, "test.txt" doesn't appear in the project. What am I doing wrong? Thanks very much for your help. | | Clay Smith Thursday, July 03, 2008 12:07 AM | Well, it turns out theObject reference not set to an instance of an object error was ocurring because I forcing the Action AddItemFromString to add a new file to a folder in the solution, not a project in the solution. Interestingly, this still resulted in the item being created, but the NullReference exception was thrown immediately afterwards.
In other words, it appears that if you're interested in using AddItemFromStringAction to create an item in a solution folder, it's not really supported and an error is thrown - but the artifact is still ultimately generated. - Marked As Answer byClay Smith Thursday, July 10, 2008 6:11 PM
- Marked As Answer byClay Smith Thursday, July 10, 2008 6:11 PM
- Marked As Answer byClay Smith Thursday, July 10, 2008 6:11 PM
-
| | Clay Smith Thursday, July 10, 2008 6:09 PM | Are you calling myAction.Execute to actually execute the action? Are you getting any errors?
Working with GAX/GAT/DSL? Download SFT now! http://softwarefactoriestoolkit.net | | vga Thursday, July 03, 2008 2:06 AM | Yes, when I call Execute() I get the following error (but the file is created):
Microsoft.Practices.RecipeFramework.ActionExecutionException: An exception occurred during the binding of reference or execution of recipe HelloWorldRecipe. Error was: Action DSLInfo failed to execute: Object reference not set to an instance of an object.. You can remove the reference to this recipe through the Guidance Package Manager. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction.Execute() at FKA.GuidancePackage1.Actions.GetClassesFromDSLFileAction.Execute() in C:\Documents and Settings\Clay\My Documents\Visual Studio 2008\Projects\GuidancePackage1\GuidancePackage1\Actions\GetClassesFromDSLFile.cs:line 73 at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionExecutionService.Execute(String actionName, Dictionary`2 inputValues) at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionExecutionService.Execute(String actionName) at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionCoordinationService.Run(Dictionary`2 declaredActions, XmlElement coordinationData) at Microsoft.Practices.RecipeFramework.Recipe.ExecuteActions(IDictionaryService readOnlyArguments, IDictionaryService arguments, ITypeResolutionService resolution) --- End of inner exception stack trace --- at Microsoft.Practices.RecipeFramework.Recipe.UndoExecutedActionsAndRethrow(Exception ex) at Microsoft.Practices.RecipeFramework.Recipe.ExecuteActions(IDictionaryService readOnlyArguments, IDictionaryService arguments, ITypeResolutionService resolution) at Microsoft.Practices.RecipeFramework.Recipe.Execute(Boolean allowSuspend) at Microsoft.Practices.RecipeFramework.GuidancePackage.Execute(String recipe, IAssetReference reference, IDictionary arguments) at Microsoft.Practices.RecipeFramework.GuidancePackage.Execute(IAssetReference reference) at Microsoft.Practices.RecipeFramework.RecipeReference.OnExecute() at Microsoft.Practices.RecipeFramework.VisualStudio.VsBoundReference.OnExecute() at Microsoft.Practices.RecipeFramework.AssetReference.Execute() at Microsoft.Practices.RecipeFramework.VisualStudio.RecipeMenuCommand.OnExec() at Microsoft.Practices.RecipeFramework.VisualStudio.AssetMenuCommand.Invoke() | | Clay Smith Monday, July 07, 2008 3:32 PM | Well, it turns out theObject reference not set to an instance of an object error was ocurring because I forcing the Action AddItemFromString to add a new file to a folder in the solution, not a project in the solution. Interestingly, this still resulted in the item being created, but the NullReference exception was thrown immediately afterwards.
In other words, it appears that if you're interested in using AddItemFromStringAction to create an item in a solution folder, it's not really supported and an error is thrown - but the artifact is still ultimately generated. - Marked As Answer byClay Smith Thursday, July 10, 2008 6:11 PM
- Marked As Answer byClay Smith Thursday, July 10, 2008 6:11 PM
- Marked As Answer byClay Smith Thursday, July 10, 2008 6:11 PM
-
| | Clay Smith Thursday, July 10, 2008 6:09 PM |
|