Motivation

Have you ever been writing code like this:

SPContext.Current.Site.Features.Add(new Guid("7F304722-681E-4237-87A0-1989FBA5EBDC"));

but would much rather write something like this:

SPContext.Current.Site.Features.Add(My.SharePoint.Solution.Features.Feature1.Id);

and were too lazy to maintain the Guids both in feature.xml and in code? Then this project might be your solution.

Description

This T4 template will search your project for feature.xml-files, validate them, and generate code with the feature guids.

Example

solution.png

Generated sourcecode:
using System;   
using System.Runtime.CompilerServices;

namespace My.SharePoint.Solution.Features
{
  [CompilerGenerated]
  public static class Feature1
  {
    public static readonly Guid Id = new Guid("430a4d5b-443c-433f-87e9-502d92d98f29");
  }
  [CompilerGenerated]
  public static class Feature2
  {
    public static readonly Guid Id = new Guid("233be6dd-4214-4284-bc6f-23492cf76aa2");
  }
}

Installation

Download T4SharePoint.tt and include it in your visual studio project (Tested with VS 2008 and SharePoint 2007).

Last edited Nov 15, 2009 at 4:42 PM by ahvam, version 7