Including External Files

You can cause CodeSmith to compile the contents of an external file into your template by using an include statement. This can be useful when you have common functions that you want to share between several templates. The include statement takes a single argument which specifies the relative path from the current template to the file to be included:

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

You can also use an include statement to bring in static template content. It doesn't matter what is in the file that you include; CodeSmith simply inserts the file contents into the template.

There are other ways to share common code between templates. In most cases, you should use other methods for code-sharing, such as the Src attribute on the [CodeTemplate|http://docs.codesmithtools.com/display/Generator/The+CodeTemplate+Directive] directive or an [Assembly|http://docs.codesmithtools.com/display/Generator/Referencing+Assemblies] directive that imports a source file. That's because these methods require full .NET class files that are easier to edit in other code editors, while an include statement will accept malformed source files.