private void ExecuteTemplate(Project project, string template) { // Try to find it so it can be run var templateItem = project.GetRelativeItem(template); // Make sure template is found if (templateItem == null) { Feedback.Error("Could not find template - " + template); return; } // Make sure correct Custom Tool is associated if (((string)templateItem.Properties.Item("CustomTool").Value) != "TextTemplatingFileGenerator") { Feedback.Error("Could not execute the Text Template.\nThe TextTemplatingFileGenerator CustomTool is not associated with the file " + templateItem.FileNames[0]); return; } // Try/catch ? var vsProjectItem = (VSProjectItem)templateItem.Object; vsProjectItem.RunCustomTool(); }