How-to: Upgrade your existing CodeSmith Generator CSLA templates from version 3.8 to 4.0

We recently released a new major version of the CodeSmith Generator CSLA templates that add support for many new features including Visual Studio 2010, CSLA 4.0 and Silverlight 4.0 support. They can be downloaded here. When upgrading to the templates and you are going from CSLA 3.8 to the latest CSLA 3.8.4 templates, there really aren’t any changes you need to make other than updating your CodeSmith Project File template location to point to the new version of the templates.  The easiest way to do this is to open up Visual Studio and double click on the CodeSmith Project File and do a replace all on that file path as this will update all file paths in all CodeSmith Project Files.

If you are upgrading from CSLA 3.8 to CSLA 4.0 then additional work is required. The first step is to convert your solution to Visual Studio 2010 and set all the projects to use the .NET Framework v4.0.

Secondly, you will need to do is go into your CodeSmith Project Settings and change the FrameworkVersion Property from v35 to v40. If you are planning on using Silverlight it is best to set the IncludeSilverlightSupport property to true to save you additional merging steps.

The next step is to regenerate the files; you will notice that there are some build errors.  This is due to the entity partial classes are not regenerated and there are some required changes for Rules or for Silverlight. If you didn’t make any changes to the non-generated partial classes (E.G. Account.cs or Account.vb), then it is safe to delete the entire class and regenerate.

Tip: if your Location property is set to a full path, I recommend setting it to “.\” without the quotes.

If this is not the case then I recommend backing up your solution if it is not under source control (highly recommended). I would copy the CodeSmith Project File to a new folder and use a program like Beyond Compare to merge the partial classes together.  Since you have already regenerated, the generated partial classes will be in sync with CSLA 4.0 and won’t require a diff so your favorite diffing program will tell you that there is no work needing to be done.

As you can see from the diff above, you will need to diff the changes. I’d recommend putting all of your Custom Code in region blocks as this makes merging much easier. This shouldn’t ever need to be merged again unless CSLA introduces some breaking changes.