Generating code from the command line

LLBLGen Pro ships with a command line tool: CliGenerator.exe for generating code from the command line. This tool is available in the LLBLGen Pro installation folder and its sourcecode is available in the LLBLGen Pro sourcecode archive.

The CliGenerator requires access to most of the LLBLGen Pro designer assemblies and the license file. It's therefore recommended, if you compile the tool from sourcecode, to place it in the LLBLGen Pro installation folder.

Validation takes place prior to executing the tool's core engine. If a validation error occurs, the CliGenerator will quit and report the validation error(s). To correct the errors, use the designer. The tool will use the preferences set as stored for the executing user, or use the defaults if no preferences are found.

The command line tool works with all supported O/R mapper frameworks and databases / database drivers. The CliGenerator return the value 1 if an exception occurred, and 0 if everything went OK. This value is used by Windows to set the %ERRORLEVEL% variable in batch files, and can be used to perform batch statement logic.

LLBLGen Pro supports multiple code generation tasks at once, and the CliGenerator does too. It validates each code generation task and if one isn't valid (e.g. information isn't available, like the destination folder), the task is skipped.

CliGenerator usage

To generate sourcecode from the command line, or e.g. in a batch file, there are several ways to use the CliGenerator. Below are the usage directives for the various use case.

Entity model only.

To generate code for the entity model only, you can use the CliGenerator.exe tool with the following command arguments (this is the usage known from v4 and earlier).

Usage:

  • CliGenerator ProjectFile RootNamespace LanguageName PlatformName TemplateGroupName PresetName DestinationFolder ClearDestinationFolder

Or:

  • CliGenerator ProjectFile RootNamespace LanguageName PlatformName TemplateGroupName PresetName DestinationFolder ClearDestinationFolder LogFile

ClearDestinationFolder can be 0 or 1. A value of 1 means clear destination folder, 0 means leave the contents.

DestinationFolder can be a relative path, which should be prefixed with .\ or ..\

GeneratorConfigName and TemplateSetConfigName can contain the start part of the full name of a configuration. The first found matching the string will be used. The utility uses a .config file which specifies the driver and taskperformer root folder. Be sure to set these config keys to the right folders if you use different folders in the LLBLGenpro.exe.config file as well. All folders are relative to the execution folder of the CliGenerator.exe.

An alternative usage:

  • CliGenerator ProjectFile DestinationFolder ClearDestinationFolder

or:

  • CliGenerator ProjectFile DestinationFolder ClearDestinationFolder LogFile

Here, the RootNamespace, LanguageName, PlatformName, TemplateGroupName and PresetName are obtained from the project file. ClearDestinationFolder can be 0 or 1. A value of 1 means clear destination folder, 0 means leave the contents. To properly use this set of arguments, use it after you've already generated code in the designer and saved the project file afterwards so these parameters have a value in the project file.

Usage examples:

CliGenerator "C:\Myprojects\NHibernate\AdventureWorksNH.llblgenproj" "NH" "C#" ".NET 3.5"
"General" "SD.NHibernate (XML mappings and classes)" "C:\Myprojects\NHibernate\Source" 1
"C:\Myprojects\NHibernate\log_AdventureWorks_CS.txt"

Short usage example:

CliGenerator "C:\Myprojects\NHibernate\AdventureWorksNH.llblgenproj" "C:\Myprojects\NHibernate\Source" 1

Multi-model

The following usage directives will generate code for multiple models (if the project contains multiple models).

Short usage

  • CliGenerator ProjectFile ClearDestinationFolders

or

  • CliGenerator ProjectFile ClearDestinationFolders Logfile

ClearDestinationFolder can be 0 or 1. A value of 1 means clear destination folder, 0 means leave the contents.

DestinationFolder can be a relative path, which should be prefixed with .\ or ..\

The short usage will simply load the project file and use all information to generate code from the project file. If no valid information is present, code generation will fail.

Multi-command usage

The multi-command usage offers a new interface which allows the specification of detailed code generation arguments per model. Code is generated for all models mentioned in the arguments, other models are ignored. If an element isn't specified in the arguments (e.g. rootnamespace), the element's value is retrieved from the project file.

CliGenerator -p ProjectFile -m <arguments> -l logfile -c

Users can specify '-m arguments' multiple times, once per model to generate code for.

The arguments to specify with -m:

  • -p specifies the project file to load
  • -c specifies that the destination folders have to be clearned. Omiting this parameter will leave the destination folders as-is
  • -l specifies the logfile to store the complete log in of all code generation cycles.
  • arguments is a set of name=value pairs separated by semicolons. These pairs are:
    • rootnamespace=value. Short: r=value
    • language=value. Short: l=value
    • platform=value. Short: pf=value
    • templategroup=name. Short: t=value
    • preset=name. Short: pr=value
    • destinationfolder=value. Short: d=value
    • modelname=value. Short: m=value. If value is left empty, the entity model is assumed.

Specifying arguments for the same model more than once will overwrite earlier parsed arguments in full. If a value contains spaces, it has to be surrounded by quotes. If an argument hasn't been specified, e.g. the language isn't specified, the value from the project file is assumed.

Example
CliGenerator.exe -p c:\temp\InheritanceOneEF6.llblgenproj -l c:\temp\ih1.txt -c 
-m m=;l=VB.NET;pf=".NET 4.5.1";d=c:\temp\generatortest\test6;pr="SD.EntityFramework.v6 (Code First)" 
-m m=DTOs;l=C#;