Add Page (with presenter) Recipe

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The guidance package includes the recipe named Add Page (with presenter). After you install the guidance package, the recipe is available on the Solution Explorer shortcut menu that appears when you right-click a folder in a Web site or the Web site root node. Figure 1 illustrates the recipe menu.

Ff709857.550829e6-6ba0-48ea-8524-d1bc8a0ad0a3(en-us,PandP.10).png

Figure 17

The Add Page (with presenter) recipe menu

When you run the recipe, the recipe framework displays a wizard that you can use to customize the generated code. Figure 2 illustrates the wizard.

Ff709857.925fc262-2298-4ff7-ad1a-cd5c5146a7fa(en-us,PandP.10).png

Figure 18

The Add Page (with presenter) recipe wizard

For detailed instructions about how to use the Add Page (with presenter) recipe, see How to: Add a Page with a Presenter.

Implementation Details

You can find the recipe definition split across the files CreateWebClientFactoryView.xml and CreateWebClientFactoryViewCommon.xml (these files are located in subfolders under the Recipes folder of the WebClientFactoryPackage project).

You use the HostData section in a recipe definition to specify where in the Visual Studio interface the recipe will be shown. In the CreateWebClientFactoryView.xml file, four command bars are defined in the HostData section.

<HostData>
  <Icon ID="689" />
  <CommandBar Menu="WCSFWebProjectFolderItem" />
  <CommandBar Menu="WCSFWebProject" />
  <CommandBar Menu="WCSFWebApplicationProject" />
  <CommandBar Menu="WCSFWebApplicationProjectFolder" />
</HostData>

The command bars have the following associations:

  • The first command bar is associated with the WCSFWebProjectFolderItem menu. The WCSFWebProjectFolderItem menu is displayed when the user right-clicks a folder in a Web site in Solution Explorer.
  • The second command bar is associated with the WCSFWebProject menu. The WCSFWebProject menu is displayed when the user right-clicks a Web site node in Solution Explorer.
  • The third command bar is associated with the WCSFWebApplicationProject menu. The WCSFWebApplicationProject menu is displayed when the user right-clicks a Web Application project node in Solution Explorer.
  • The fourth command bar is associated with the WCSFWebApplicationProjectFolder menu. The WCSFWebApplicationProjectFolder menu is displayed when the user right-clicks a folder in a Web Application project node in Solution Explorer.

The WCSFWebProjectFolderItem menu, the WCSFWebProject menu, the WCSFWebApplicationProject menu, and the WCSFWebApplicationProjectFolder menu are defined in the file WebClientFactoryPackage.xml located in the root of the WebClientFactoryPackage project.

<Menu Name="WCSFWebProject" Text="Web Client Factory" Priority="1">
  <CommandBar Name="Web Project"/>
</Menu>
<Menu Name="WCSFWebProjectFolderItem" Text="Web Client Factory" Priority="1">
  <CommandBar Name="Web Folder"/>
</Menu>
<Menu Name="WCSFWebApplicationProject" Text="Web Client Factory" Priority="1">
  <CommandBar Guid="D309F791-903F-11D0-9EFC-00A0C911004F" ID="1026"/>
</Menu>
<Menu Name="WCSFWebApplicationProjectFolder" Text="Web Client Factory" Priority="1">
  <CommandBar Guid="D309F791-903F-11D0-9EFC-00A0C911004F" ID="1073"/>
</Menu>

The files created by the recipe (the page implementation, the presenter, and the page's interface) are generated from T4 templates. You can use T4 templates to write complex templates with embedded code that is executed when the template unfolds. The following actions in the recipe definition unfold the T4 templates for the page's files.

<Action Name="GenerateViewWebFile"
      Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="IsWCSFSolutionWAP" RecipeArgument="IsWCSFSolutionWAP"/>
  <Input Name="WebsiteNamespace" RecipeArgument="WebsiteNamespace"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewCodebehind"
Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewCodebehindPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewDesigner"
Type="TextTemplateAction"
Condition="$(IsWCSFSolutionWAP)">
  <Input Name="Template" RecipeArgument="T4ViewDesignerPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewPresenter"
      Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewPresenterPath"/>
  <Input Name="ModuleName" RecipeArgument="ModuleName"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace"/>
  <Input Name="ViewsFolder" RecipeArgument="ViewsFolder"/>
  <Output Name="Content" />
</Action>
<Action Name="GenerateViewInterface"
Type="TextTemplateAction">
  <Input Name="Template" RecipeArgument="T4ViewInterfacePath"/>
  <Input Name="ViewName" RecipeArgument="ViewName"/>
  <Input Name="ModuleNamespace" RecipeArgument="ModuleNamespace"/>
  <Input Name="ViewsFolder" RecipeArgument="ViewsFolder"/>
  <Output Name="Content" />
</Action>

Note

Note: For detailed information about T4 templates, see the Guidance Automation Toolkit documentation.
You can only add pages to modules with names that are valid C# or Visual Basic identifiers. If you do not (for example, you try to add a page to a module that has a period in its name), the generated class name for the page will not be a valid identifier and the code will not compile.