CodeSmith has a great feature that allows you to use XSD schemas to load XML properties into code templates. However, the classes that CodeSmith generates from the XSD are not identical with those produced by XSD.exe. This can lead to problems when writing custom templates or when converting CodeSmith templates into standalone assemblies that depend on the XML properties.
I saw a recent post in the CodeSmith forums where other developers were also struggling with this issue. Eric Smith (the creator of CodeSmith) responded that a command line tool for generating compatible classes from an XSD will be included in version 4.0 of CodeSmith, but there is no set date for its release....so I decided to take matters into my own hands.
XSD2CS (download here) is a Custom Tool Add-In to Visual Studio that converts an XML schema into CodeSmith-compatible classes in C#. Using this tool, you can add an XSD to a Visual Studio project and then automatically generate the same classes that CodeSmith uses, allowing you to use both the CodeSmith explorer and Visual Studio to develop your standalone templates.
Setup
To setup the XSD2CS custom tool, you must have CodeSmith version 3.2 installed. Navigate to the XSD2CS installation folder and edit the setup.bat file so that it points to your CodeSmith install directory as well as to your .NET Framework bin directory. Run the setup.bat file to copy the CodeSmith.Engine.dll, export the types in XSD2CS.dll to COM and add the appropriate Registry entries for this custom tool.
Usage
Once you've created your XSD file, add the file to your project and set the Custom Tool property to "CodeSmithXsdConverter" (no quotes). After you've done that, you'll get an associated .cs file. To see it, make sure that Show All Files is selected at the top of the Solution Explorer. From then on, whenever you change the contents of your XSD file, the classes will be regenerated.
Technorati : Code Generators, CodeSmith, Custom Tool, XmlProperties, Xsd
Del.icio.us : Code Generators, CodeSmith, Custom Tool, XmlProperties, Xsd