Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Create files in a new folder
 

Create files in a new folder

Hi,

I have an Action which creates a file (t4) in a project. The name of the class is retrieved by an argument.

How do I create a new folder, and add the file to that folder? The name of the folder has to be the same as the file (the argument)

Heres a code snippet of the scenario :

<Action Name="GenerateViewElement" Type="Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TextTemplateAction, Microsoft.Practices.RecipeFramework.VisualStudio.Library"

Template="Text\ViewItem.cs.t4">

<Input Name="ClassNameView" RecipeArgument="MultiElementName" />

<Output Name="Content" />

</Action>

<Action Name="GetViewProjectAction" Type="Microsoft.Practices.RecipeFramework.Library.Actions.GetProjectAction, Microsoft.Practices.RecipeFramework.Library">

<Input Name="ProjectName" RecipeArgument="DefProjectView"/>

<Output Name="Project" />

</Action>

<Action Name="AddViewClass" Type="Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction, Microsoft.Practices.RecipeFramework.Library"

Open="true">

<Input Name="Content" ActionOutput="GenerateViewElement.Content" />

<Input Name="TargetFileName" RecipeArgument="TargetFileView" />

<Input Name="Project" ActionOutput="GetViewProjectAction.Project" />

</Action>

Thanks in advanced

Nima_DK  Thursday, October 18, 2007 9:02 AM
Hi Nima,
what Dhawal posted is the best approach so, there are no way to move project items in an easily way. But if you want to do that, you have to remove the item and add it again to the destination parent. So, extend the AddItemFromStringAction action doing the same what Dhawal wrote.

hth
jose.
Jose Escrich  Thursday, November 01, 2007 2:46 PM
Hi Nima_DK



I tried overriding Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction and wrote the following in the execute override


public override void Execute()
{
System.Diagnostics.Debug.Assert(false); //for attchiing the debugger
//add a folder with the required name
EnvDTE.ProjectItem folder = this.Project.ProjectItems.AddFolder(TargetFileName, "");

TargetFileName + =".cs";
//now add the file by calling base.execute. this will add directly in proejct
base.Execute();

// Lets move the file in the created folder
Microsoft.Practices.RecipeFramework.Library.Solution.Actions.MoveProjectItemAction m = new Microsoft.Practices.RecipeFramework.Library.Solution.Actions.MoveProjectItemAction();

//move the file inside created folder
//somehow this doesent work
m.ProjectItems = folder.Collection;
m.ProjectItem = this.ProjectItem;
m.Execute();


}

Here MoveProjectItemAction is not behaving as i expected it to. the file that gets created by base.Execute actually dissapears when m.execute is called

Somebody from the GAT team will be able to tell us how do we move a fille or project item from one place to another
Dhawal B Kapadia  Friday, October 19, 2007 11:47 AM

Hi Dhawal B

Thank you for your post. I'm still waiting for the GAT team to tell us how to move a file or project item from one place to another.

/Nima

Nima_DK  Thursday, October 25, 2007 8:57 AM
Hi Nima,
what Dhawal posted is the best approach so, there are no way to move project items in an easily way. But if you want to do that, you have to remove the item and add it again to the destination parent. So, extend the AddItemFromStringAction action doing the same what Dhawal wrote.

hth
jose.
Jose Escrich  Thursday, November 01, 2007 2:46 PM
Why bother using the microsoft action to create the file in the project, and then have to move it into the folder?

Why not just write the file yourself (using the fullpath from the new folder), and then add it to the project yourself?


Ben Scott - Aust  Friday, November 02, 2007 1:01 AM

You can use google to search for other answers

Custom Search

More Threads

• Slow Wizard Input using MonitorArgument
• Unable to load type System.Collections.Generic.Dictionary
• Some arguments not being replaced in item template
• wizard appearance
• Trying to better understand the CreateProjectAction?
• web project template, to fire code in gac class.
• Boolean Condition Doesn´t Work
• How to create a database project with template?
• GAT on Visual Studio Release Candidate
• Exception: Unabe to et installer types in the C:\Program Files....\MetaGuidancePackageInstaller.dll assembly