Using a CodeSmith Project to Generate Anywhere

CodeSmith Generator Project

CodeSmith Generator Projects manage groups of CodeSmith Generator templates and their outputs all in a single CodeSmith Generator Project file. CodeSmith Generator Projects are files that enable you to run an entire generation process at anytime in a simplistic manner from many different environments.

About

A CodeSmith Project file uses a .csp file windows extension, and stores XML metadata about your CodeSmith Project.

See: Anatomy of a Project File

Generation Capabilities

CodeSmith Project files enable the management and execution of a generation process in many environments.

Windows Explorer

Managing a CodeSmith Project right from Windows Explorer is simple and doesn't require you to use CodeSmith Studio to manage a project. Options are available through the right-click context menu your CodeSmith Project file (.csp).
The menu options include:

  1. Generate Outputs
  2. Manage Outputs
  3. Add Outputs

Command-Line

You can Generate Outputs of a CodeSmith Project in the command line by using the CodeSmith Console application. 
You would simply call:
cs MyCodeSmithProject.csp

Visual Studio

The tight integration with Visual Studio allows you to fully manage any CodeSmith Project right from Visual Studio. To manage a CodeSmith Project, you can use the Right-Click context menu of a CodeSmith Project file from the Solution Explorer window.
The menu options include:

  1. Generate Outputs
  2. Manage Outputs
  3. Add Outputs
  4. Output OptionsYou can use ActiveGeneration quite easily in your Visual Studio projects now, simply by specifying the BuildAction of your CodeSmith Project.  Setting the BuildAction = "Generate" in the properties of you CodeSmith Project file in the Solution Explorer will cause your entire build process to occur prior to your project building.

CodeSmith Studio

To manage a CodeSmith Project, you can use the Right-Click context menu of a CodeSmith Project file from the CodeSmith's Template Explorer window.   The menu options include:

  1. Generate Outputs
  2. Manage Outputs
  3. Add Outputs

MSBuild

CodeSmith projects can be manually expected from your MSBuild project file by executing:
<CodeSmith ProjectFile="MyProject.csp" />

When you set the BuildAction to Generate in Visual Studio, you're actually using the CodeSmithGenerate Target, located in:
 Program Files\MSBuild\CodeSmith\CodeSmith.targets
*  *You can import this target in your Visual Studio Projects by using the Import tag.
 <Import Project="$(MSBuildExtensionsPath)\CodeSmith\CodeSmith.targets" />

Using a Generator Project from MSBuild