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!!!



