Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

 

After reading this document you will know how-to download, install and use the CodeSmith Generator SDK in your applications. This document will also demonstrate the most common uses of the CodeSmith Generator API:

...

Download

After logging into your account, visit the following the downloads section to download the latest version of CodeSmith Generator.

Info
It is recommended that you download the Zipped Version of CodeSmith Genreator Generator as it includes all of the assemblies that you will need to reference in your SDK application.  

...

Info
A C# and VB.Net sample SDK project exists in your extracted samples under the following directory (Documents\CodeSmith Generator\Samples\<VERSION>\Projects\CSharp\APISample). You may need to do some minor changes like changing the ConnectionStringConnection String.
Info
A project using an SDK license must be Strong-Named.

...

Next, you are required to reference the following assemblies:

  • ActiproSoftware.Text.Wpf.dll
  • CodeSmith.Core.dll
  • CodeSmith.Engine.dll

 

Info
These assemblies will be located in the CodeSmith Generator's Program Files folder if you installed CodeSmith Generator.

...

In the example below we will also need to reference the following assemblies:

  • CodeSmith.BaseTemplates.dll
  • SchemaExplorer.dll
  • SchemaExplorer.SqlSchemaProvider.dll

...

Code Block
languagecsharp
public static void Main(string[] args) {
    CodeTemplateCompilerstring compilerpath = new CodeTemplateCompiler(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\\..\\StoredProcedures.cst");
    compiler.Compile();
    if (compiler.Errors.Count == 0)var engine = new TemplateEngine(new DefaultEngineHost(System.IO.Path.GetDirectoryName(path)));


    {CompileTemplateResult result = engine.Compile(path);
     CodeTemplate template = compiler.CreateInstance();if (result.Errors.Count == 0) {
        DatabaseSchemavar database = new DatabaseSchema(new SqlSchemaProvider(), @"Server=.;Database=PetShop;Integrated Security=True;");
        TableSchema table = database.Tables["Inventory"];


        CodeTemplate template = result.CreateTemplateInstance();
        template.SetProperty("SourceTable", table);
        template.SetProperty("IncludeDrop", false);
        template.SetProperty("InsertPrefix", "Insert");
        template.Render(Console.Out);
    }     else
    {
        forforeach (intvar ierror = 0; i < compiler.Errors.Count; i++)
        {in result.Errors)
              Console.Error.WriteLine(compilererror.Errors[i].ToString());
   
    }

   }     Console.WriteLine("\r\nPress any key to continue.");
    Console.ReadKey();
}
Info
TemplateEngine also features Async methods to compile templates Asynchronously.

The above code will compile and run but requires the Stored Procedures template that can be found in the APISample project that was mentioned above. If you have any SDK API questions feel free to contact support.

Info
In addition to the methods shown in this sample, you may also find the CodeTemplate.RenderToFile() and CodeTemplate.RenderToString() methods useful; they let you direct the output of your templates directly to a file or to a string variable.