Including external files

An include statement makes CodeSmith Generator insert the contents of another file into your template and compile them as part of it. This is one way to share common functions between templates. The statement takes the path of the file to include, relative to the current template:

<!-- #include file="CommonScript.cs" -->

The included file can contain anything, including static template content: Generator simply inserts the file's contents into the template.

Important

In most cases, use one of the other ways to share code instead, such as the Src attribute of the CodeTemplate directive or an Assembly directive that compiles a source file. Those methods require complete .NET class files, which are easier to edit in other code editors. An include statement accepts source files that aren't valid on their own.