Sunday, January 13, 2008

Problem with Unregistering Guidance Package

If you run “Unregister Guidance Package” recipe or uninstalled Guidance Package and still can see Package in “Add New Project” dialogue you may have to follow these steps.



Go to directory ‘C:\Documents and Settings\All Users\Application Data\Microsoft\Recipe Framework’
You will find file ‘RecipeFramework.xml’ here.
This file contains entries for all Guidance Package which are installed on machine.
Ensure if entry is removed from here after uninstalling guidance package.




If problem still persists go to registry and browse to key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages’

Here you will find folder which starts from ‘77’. For example:







This key will have folder named ‘Templates’ which has entries for all Guidance Packages installed on machine. Check each key to find your Guidance package. Attribute PackageName will help to find this.
Once you found you package entry copy key and search in whole registry and delete wherever found.


Close registry and open “Add New Project” Dialogue from Visual Studio. Entry for uninstalled package would have removed now.

Wednesday, November 21, 2007

Guidance on GAT Scenario 2

Scenario 2:

You need to add item say “web.config “ to folder say “Administration” present inside project by copying web.config file from Templates folder of your guidance package.
Exact path of file inside Templates folder is “Templates\Solutions\Projects\AspNetWebSite\Administration”

Obvious Solution:

By looking at scenario this is quite simple task and can be done by using already existing action provided by patterns and practices group.
Action class to be used:

Microsoft.Practices.RecipeFramework.Extensions.Actions.VisualStudio.AddItemFromFileToProjectItemAction

Library which has this class is Microsoft.Practices.RecipeFramework.Extensions
Now this action has few inputs

InputProjectItem of type EnvDTE.ProjectItem – This is obvious input for specifying ProjectItem in which you need to add web.config file. In this scenario it is Administration Folder.

SourceFileName of type string – This is input for specifying file which you need to add. In this scenario it is “Web.config”

SourceFilePath of type string – This is input for specifying path where Source file exists which needs to be copied in folder and to be added as project item. Now logically this path will be a relative path of web.config file in templates folder. So we set it to “Templates\Solutions\Projects\AspNetWebSite\Administration”.
By providing all above inputs we expect that file web.config from folder Templates\Solutions\Projects\AspNetWebSite\Administration will be copied to my project as project item under Administration project folder.

Folder path “Templates\Solutions\Projects\AspNetWebSite\Administration” will be available at location where your Guidance package is installed. And this contains file web.config too.

Action tag will look like this




But still when you run the recipe it throws error




By doing some more R & D, I found that if you specify SourceFilePath as exact path of “Web.config” file on your machine which needs to be copied and added in project folder, this action works perfect. So if you do this Action tag will look like this



But hardcoding such path in action tag is strictly not acceptable. We want our Guidance package to run smoothly from any location where developer is installing it.

My Solution:

Easiest solution is to create your own custom action which will perform the required task smoothly. We can use EnvDTE library to add item from file.

Now EnvDTE.ProjectItem has method to add project item by file copy action.
ProjectItem.ProjectItems.AddFromFileCopy(filenamewithfullpath);

Now how to get this full path?

One way is to use reflection to get current executing assembly path and append this path to our folder “Templates\Solutions\Projects\AspNetWebSite\Administration”

Second way is to use IConfigurationService is Action class

Code will look like




Append this path variable with our folder “Templates\Solutions\Projects\AspNetWebSite\Administration”

Hope this helps!!!

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