Console Application Usage

The CodeSmith Generator console application, cs.exe, runs Generator projects from the command line. For example, to generate the outputs of the PersonArray.csp project:

cs.exe PersonArray.csp

Command-line switches

Switches start with / or -, and they're case-sensitive: type them in lowercase. To show usage information, run cs.exe /? (or -?, /help or -help). --help isn't recognized.

Input

Switch Description
<file> One or more Generator project files (.csp) to generate.
/property:<name>=<value>, /p:<name>=<value> Sets a property value. See Setting property values.
/upgrade:<output>, /u:<output> Upgrades a custom tool or batch file from an earlier version of CodeSmith to a Generator project file, and saves it as <output>. Give the file to upgrade as <file>.
@<file> Reads more arguments from a response file.

Compiler

Switch Description
/debug[+|-] Emits (or suppresses) debugging information, so you can attach a debugger to a running template.
/tempfiles[+|-] Keeps (or deletes) temporary files. If /debug is on, temporary files are also kept.

Other

Switch Description
/verbose, /v Shows verbose messages.
/nologo Hides the copyright message.
/?, -?, /help, -help Shows usage information.

For the maintenance switches, such as /clearcache, see Maintenance commands.

Setting property values

The console needs values for the properties of the templates you run. You can supply them in two ways:

  • In a Generator project file, which stores the property values for each output.

  • On the command line, with the /property switch:

    /property:<name>=<value>
    /p:<name>=<value>
    

To set several properties, use the /property switch more than once, or separate the assignments with semicolons, for example /p:Namespace=Sample;ClassName=Person. Only properties whose types can be converted to and from a string can be set this way.

Important

If you set a property both in the project file and on the command line, the command-line value wins.

Examples

Command What it does
cs sample.csp Generates the outputs of sample.csp.
cs sample.csp /p:property1=sample Generates the outputs of sample.csp, setting property1 to sample.
cs customtool.xml /u:newproject.csp Upgrades the custom tool file customtool.xml to the project file newproject.csp.
cs batch.xml /u:newproject.csp Upgrades the batch file batch.xml to the project file newproject.csp.

Note

The usage information that cs.exe /? shows writes the upgrade switch as /upgrade=<output>. Use a colon instead: /upgrade:<output> or /u:<output>.

Output file names

Each output in a Generator project has a file name. By default, the name comes from the template, which sets it by overriding the GetFileName method. For example, a C# template with a ClassName property might use:

<script runat="template">
public override string GetFileName() {
    return ClassName + ".cs";
}
</script>

To change an output's file name, see Adding and editing outputs.

Maintenance commands

Command What it does
cs.exe /resetsamples Resets the sample templates to their default versions.
cs.exe /resetmaps Resets the maps to their default versions.
cs.exe /clearcache Removes all cached templates and property values. Generator also removes invalid cache entries automatically every time it runs.
cs.exe /resetlicense Resets your licensing information, in case you're having licensing problems.
cs.exe /resetconfig Resets your configuration to the defaults.
cs.exe /resetall Resets your configuration, samples, maps and licensing information to the defaults.

Each reset command asks you to confirm. Press Y to continue.

Warning

Resetting your configuration removes all of your settings, including your data sources and Template Explorer shortcuts.