Code Generation For Tridion Introduction

Introduction CG4T

On this page, I will explain a little bit about my Visual Studio extension: Code Generation For Tridion

Tridion (now also known as SDL Web 8) is an Enterprise Content Management System. One way (& the most common way) is to use it for managing sites. This extension generates code for:

  • dynamic websites working with the DD4T framework.
  • dynamic website working with the SDL DXA framework
  • applications that use the SDL Tridion Core Service

Overview of what it can do for a developer

It can (re)generate C# classes by connecting to the Core Service of an SDL Tridion 2013 or SDL Web 8 environment. After setting up the connection, you are able to generate the following class types:

  • ViewModel classes for DD4T web application (based on schemas).
  • ViewModel classes for DXA web application (based on schemas).
  • Schema Constants class (based on available schemas in a publication).
  • Publication Constants class (based on available publication within a Tridion environment).
  • Category Constants class
  • ... and more

Where to find CG4T

This extension for developers can be found in the VS Marketplace: Besides manual download, it is also possible to install it from within VS Extension and Updates. (See next paragraph)

Installing the CG4T extension

Now that we know what it can do, the first step is to install the Visual Studio extension itself. Search in the VS gallery for 'CG4T' and you should see:


After installing and restarting Visual Studio you will see a new 'Tridion' menu option in the header menu:

Setting up the connection

For each VS Solution, you need to setup the connection once via the wizard (Tridion -> setup connection). You should see a dialog like this:

You should use NetTCP option if possible since it is much faster for retrieving data. After successful testing, the connection the settings can be saved to a config file for future use. Actually, there are two files generated:

  1. A file with connection settings: CG4T-personaldata.json. Contains personal credential data, should not be pushed to a source code repo (add to .gitignore or other..). Credentials are encrypted.
  2. A file with project preference settings: CG4T-projectsettings.json Common settings that can be used by the whole team, should be pushed as a source code file.

Both files are stored in the same folder as the Solution file (.sln). More detailed information about the configuration files can be found on the CG4T configuration details page.

Generating code

To give you a brief overview of what to expect I created some pages to take you through the steps of generating project code:

Project settings

See the special: CG4T settings page

Feedback == fun

I hope you will try it out and like the way it works. If so (or not), please let me know. You can give comments and stars on the VS Marketplace page.