MVP
15 Sep 2009

With Create Component you can quickly add instances of the sample template components to your existing solution. You simply select the component type and specify the name of the new component; all other actions are automated. The component is created automatically in the correct project and folder, its namespace is set accordingly, and if the correct project is not present in the solution it is added on the fly with all correct namespaces, project settings etc.

Create Component is a feature that was added to the Macaw Solutions Factory in version 2.1.

Note: there are several series of Macaw Solutions Factory posts, on multiple blogs.
You can read all posts on the Macaw Solutions Factory site, or use this feed.

Basically, the Create Components feature allows you to think and work quickly at the logical level when creating components. You do not need to think about which project, folder, project items or settings are needed to implement the component. Instead, all that stuff is generated for you; you can start directly with implementing the component’s internals.

The Create Component feature only works on MSBuild-based projects, so this feature is not available in the Bts2006 and the Sql2008 or Sql2005 SS*S solutions.

This is how Create Component works in detail:

  1. You start by creating a baseline solution with the MAST Solution Builder, by selecting an action in the Factory Guide under ‘Create Functional Area’.

    All you need to do now is type the name of the new Functional Area (VS solution), and select which components types (VS projects) the Functional Area should contain initially.
    Note that you only need to select the component types (projects) of which you know for sure that you will need them; you can add component types to an existing solution any time you want.
    When you click Create, the new solution is built and all namespaces, project settings etc are set to the correct values.After you close the solution builder window, you will be asked whether you want to remove the sample components and sample code from the new solution:

    And whether you want to open the new solution:

    After you make these choices, the Product.config file will be opened in VS instance where you selected the ‘Create Functional Area’ action, and the new Functional Area will be added automatically to the first non-Templates machine role:

    If you have more than one machine role – other than Templates – in your product, you may want to move the Functional Area to a different machine role now.

  2. When the new solution is opened in VS you will see a node ‘Create Component’ in the Factory Guide, with a lot of actions in it:
    In any non-Templates solution these Create Component actions are generated on the fly, based on the Sample components in the Templates Functional Area for the current Product Dependency.
    E.g. in the DotNet3Templates.sln you can easily recognize the sample components that correspond to the actions in above screenshot:

    For each project item in a template solution whose name starts with ‘Sample’, an action is generated under Create Component. The name of the action specifies both the project name and the component name (without ‘Sample’).
    If a template project does not contain any sample components, an action is generated to only add the project to your solution (e.g. ‘New OperationalManagement’ in the above screenshot).

    You can easily modify the template solutions to change, add or remove sample components. You need to select the “Refresh ‘Create Component’ actions” action to regenerate the actions after you make this type of changes.

  3. When you execute a Create Component action, you are prompted for the component name and everything else is done automatically:

    When you select OK, the component is added and it is opened in the editor:
    If necessary, the proper project for the new component will be created on the fly. You can see whether this will happen beforehand in the name prompt dialog:

    When you select OK, the MAST solution builder window will open and the new project will be created:

    As you can see in the log window the solution builder performs a lot of actions automatically, e.g. setting namespaces and project properties, and adding the project target to the FxCop project file for this solution.

    When you close the MAST solution builder window, the new component will be added and it is opened in the editor:

     

  4. The new component that you added contains example code, to show you a typical implementation pattern.
    This sample code is marked with “region Sample” and “endregion Sample” texts – the exact syntax is specific for the file type (.cs, .xml, .sql, .aspx, .ascx etc.).
    If you do not need the sample code, you can quickly remove it from a new component by selecting the Factory Guide action “Remove Sample Content From Active Document”:

Even though the description of what Create Component does for you is quite long, using it is really quick and simple:

  1. Click on the Create Component action for the component type that you want to add
  2. Supply the name for the new component

Easy does it. Njoy!

About the Author
Vincent Hoogendoorn is a Microsoft MVP Developer Technologies with over 20 years of experience as hands-on .NET innovator / architect / engineer. He is currently focused on full stack C#: Microsoft Orleans backends and browser/native frontends with C# Markup 2 for Windows App SDK, Uno Platform and Xamarin/Maui. Xamarin cross-platform mobile veteran, passionate about developer productivity. Principal Software Engineer at InnoWvate.NET, Technical Director at Applicita.

Leave a Reply


*

captcha *