Thursday, November 15, 2007

Guidance on GAT using scenarios

In this series I am planning to put my leanings and solutions to few problems which I faced during Guidance Package Development. Hope this will help for new GAT learners like me :)

I am using scenarios to explain problem and its solution.

Scenario 1:
You need to add new folder named “Administration” inside your web project (or any other .Net project)

Obvious Solution:

By looking at scenario I thought this is very common action which almost everybody needs. So it must be provided by Patterns and Practices group.

I started looking for action in Microsoft.Practices.RecipeFramework.Extensions library. I found action class AddSolutionFolderAction but this cannot be used in our scenario as we need to add folder in project rather than in solution.

My Solution:

So very easy solution for above scenario is to write your own custom action.
This action will perform required task of adding folder in project.

To pragmatically add folder inside project we can use EnvDTE assembly . If you need help of this assembly you can visit msdn2.microsoft.com/en-us/library/envdte(VS.80).aspx

Now this action will take two inputs.

Project: This will be of type EnvDTE.Project in which folder needs to be added.

Foldername: This will be name of folder which need to be added in Project.

Action will add folder with given FolderName and will give added folder as output (FolderProjectItem). This will be of type EnvDTE.ProjectItem which can be used further if required.

The Code will look like this.






Now similarly one can write simple action to add folder inside folder of project.
Code will look like this



No comments: