Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Urgent - Create a new Item (Form)
 

Urgent - Create a new Item (Form)


I have a Windows Application and I need to create a GAX package that will:

1- Add a new item to the project menu to start a new wizard.
2- Collect some user data (usedatagrid, allowCRUD, etc) and with it create a new Form and implement on it some interfaces.

How can I accomplished that?

So far I was able to create the new item on the project menu by adding a Recipe and implement an action to create a new class (just the .cs file) using TextTemplateAction and T4. But the problem is getting GAX to create the Form (Form1.cs and Form1.Designer.cs)


Please help!!!

Mateus
mateusmorato  Tuesday, August 28, 2007 12:06 AM
This is a fragment from an empty GAT Guidance Package. The first action (TextTemplateAction) generated the template using the "YourTemplateFileName.cs.t4" and it saves the output (string) in the Content variable.

Then the AddFromStringAction uses the GenerateClass's Content to add the file to the TargetProject.

<Action Name="GenerateClass" Type="Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TextTemplateAction, Microsoft.Practices.RecipeFramework.VisualStudio.Library"
Template="YourTemplateFileName.cs.t4" >
<Input Name="ClassName" RecipeArgument="ClassName" />
<Output Name="Content" />
</Action>
<Action Name="AddClass" Type="Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction, Microsoft.Practices.RecipeFramework.Library"
Open="true">
<Input Name="Content" ActionOutput="GenerateClass.Content" />
<Input Name="TargetFileName" RecipeArgument="TargetFile" />
<Input Name="Project" RecipeArgument="TargetProject" />
</Action>

HTH
-Adrian
Adrian Alonso  Tuesday, August 28, 2007 2:49 PM
Hi Mateus, I think you are in the right direction. If you want a general guidance on how to implement your scenario you could take a look at the source code of the p&p software factories in order to see how this is accomplished by them (this is a quite common scenario so I think it won't be hard to find a recipe that does something similar).

If the problem that you are having is specific please tell us a little more about it. (for example, if you are having problems adding the designer file as a child of the Form.cs file).

HTH,
-Adrian


Adrian Alonso  Tuesday, August 28, 2007 1:36 PM

That's the problem.... How can I create the file and the designer class and add it to the project.

I'll try to look at the source code but if you have a sample I'll appreciate....

mateusmorato  Tuesday, August 28, 2007 2:40 PM
This is a fragment from an empty GAT Guidance Package. The first action (TextTemplateAction) generated the template using the "YourTemplateFileName.cs.t4" and it saves the output (string) in the Content variable.

Then the AddFromStringAction uses the GenerateClass's Content to add the file to the TargetProject.

<Action Name="GenerateClass" Type="Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.TextTemplateAction, Microsoft.Practices.RecipeFramework.VisualStudio.Library"
Template="YourTemplateFileName.cs.t4" >
<Input Name="ClassName" RecipeArgument="ClassName" />
<Output Name="Content" />
</Action>
<Action Name="AddClass" Type="Microsoft.Practices.RecipeFramework.Library.Actions.AddItemFromStringAction, Microsoft.Practices.RecipeFramework.Library"
Open="true">
<Input Name="Content" ActionOutput="GenerateClass.Content" />
<Input Name="TargetFileName" RecipeArgument="TargetFile" />
<Input Name="Project" RecipeArgument="TargetProject" />
</Action>

HTH
-Adrian
Adrian Alonso  Tuesday, August 28, 2007 2:49 PM

But how can I write a t4 template that will generate the class and the designer?

thanks for your help!

mateusmorato  Tuesday, August 28, 2007 4:36 PM

Thanks Adrian....

I saw how can I do it looking at the WebClientFactory source code...

mateusmorato  Tuesday, August 28, 2007 5:02 PM
Great! There is a lot of cool stuff in the source code of the factories to learn how-to implement many common scenarios.

-Adrian
Adrian Alonso  Tuesday, August 28, 2007 5:16 PM

You can use google to search for other answers

Custom Search

More Threads

• Update guidance already installed
• Guidance Package versioning
• Problem Loading Package
• Microsoft.Office.Interop.Excel.Applicatio not defined
• Installing GAT on Vista with Orcas Beta1
• GAX installed but not showing in VS 2008
• Using Experimental Hive
• Some arguments not being replaced in item template
• Extending Designer Toolbox
• Project templates do not appear in VS 2005 Pro after installing GAX and GAT?