SharePoint productivity templates for CodeSmith

, , ,

For quite some time I have been busy with trying to increase my productivity while working on SharePoint solutions. In the last two years I helped design a couple of tools and developed a few of them myself: all that to simplify the most common tasks and be able to focus on the solution-specific things. Recently I have focused on code generation: based on the information already present either in SharePoint or in your solution generate source code. You can see a part of the results of my efforts in Imtech Fields Explorer: generating wrapper classes and Page Layouts. What I’ve learned is that generating source code with code can get really complex. But just recently I’ve found a simpler way to get the things done: introducing Imtech SharePoint Templates for CodeSmith.

CodeSmith?

CodeSmith is a template driven source code generator. If you’ve never heard of this tool you should definitely check it out at codesmithtools.com.

Available templates

In the first version of Imtech SharePoint Templates for CodeSmith I have included the same templates that are available in Imtech Fields Explorer:

  • GenerateContentTypeBinding – Generates the ContentTypeBinding element for the given Content Type and List. Use it every time you need to bind a Content Type to a Document Library or a List using a FeatureGenerating the ContentTypeBinding element using the GenerateContentTypeBinding template
  • GeneratePageLayout – Generates Page Layout for the given Content Type. Generated Page Layout contains display and edit controls for all non-hidden fields from the given Content TypeGenerating a Page Layout from a Content Type using the GeneratePageLayout template
  • GenerateWrapperClass – Generates wrapper class for the given Content Type so that you can reference all fields from that Content Type using code with intellisense instead of fiield names (hard-coded strings)Generating wrapper classes for a Content Type using the GenerateWrapperClass template

To really convince you how easy it is to create new templates with CodeSmith I have added two additional templates (not available in Imtech Fields Explorer):

  • FeatureElementFiles – Generates ElementFile element for every file in the given directory and its subdirectories. Extremely useful for Features like branding where you have to provision many different files using a FeatureGenerating the contents of Feature.xml file using the FeatureElementFiles template
  • FeatureModuleFiles – Generates contents of a Feature Element Manifest (commonly named as Elements.xml or ProvisionedFiles.xml). The template includes all files from the given directory and its subdirectories. Files with names Feature.xml, Elements.xml and ProvisionedFiles.xml are excluded from the output. The contents of every folder are being stored in a separate module. The template distinguishes different modules based on the name of the folder (supported: PageLayouts and MasterPages). By default all assets are being provisioned to the Style Library directory.Generating the Feature Element Manifest for a Feature using the FeatureModuleFiles template

So why CodeSmith?

As I’ve already mentioned: three of the five templates have already been available in the Imtech Fields Explorer. Why moving them to a commercial product like CodeSmith?

I have worked with generating source code with code for a couple of months now and compared my experience to using CodeSmith for a couple of weeks. The main reason for me to move to CodeSmith is the easy of creating new templates. CodeSmith’s templates use ASPX-like syntax with a couple of CodeSmith-specific directives. You can create new templates within a few minutes and the best part is that it’s all just text so you can edit them and immediately see the results.

Using CodeSmith’s templating engine makes the templates more manageable. Instead of storing the generated code in a StringBuilder, constantly appending new lines and worrying about the proper formatting and indenting you can now focus on what the template really must generated and let CodeSmith take care of the rest.

Let the product speak for itself: check out the SharePoint templates I’ve made. If you don’t have a licensed version of CodeSmith you can download the trial version from codesmithtools.com. Don’t waste any more time with coding stuff you can generate!

Download: Imtech SharePoint Templates for CodeSmith (MSI, 347KB)


Possibly related posts

5 Responses to “SharePoint productivity templates for CodeSmith”

  1. matrixgoh Says:

    Why so many people like to design code generation template in codesmith and not T4?

    Can you share some of your opionion with me.

    Thanks

  2. Waldek Mastykarz Says:

    @matrixgoh: I don't think there is one clear answer to your question. In my case it was the UI and how easy I could get started. Thanks to your comment I gave it another chance and stumbled upon Scott Hanselman's article on T4 (http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx). Who knows maybe I will give T4 a chance and will see what the pros and cons of both approaches are.

  3. mota cano Says:

    Good morning

    I´m marco mota, developer Spanish
    I need your *.cst of codesmith for working in new project.
    Are you templates free pay??¿?¿ I can´t downloading of site codeplex

    http://imtech.codeplex.com/releases/view/39782

  4. Waldek Mastykarz Says:

    I'm afraid you're using a wrong link. The templates are available @ http://imtech.codeplex.com/releases/view/27439.

  5. marco Says:

    steps:
    a) downloading Imtech.CodeSmith.Setup.msi
    b) install

    and msgbox notification with

    'could not access network location \Addins'

Leave a Reply

Security Code:

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS
Copyright © 2007 - 2012 Waldek Mastykarz

Creative Commons License