Edit Tridion Razor Mediator TBBs in Visual Studio
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Version history

  • version 2.7. Compatible with Visual Studio 2010-2013 and Tridion 2013 SP1. Doesn't include debugging.
  • version 3.1. Compatible with Visual Studio 2015 and Tridion 2013 SP1. Includes debugging.
  • version 4.0. Compatible with Visual Studio 2015 and SDL Web 8. This version is located in branch web8.

Main functionality

Possibility to work with Tridion content in Microsoft Visual Studio:

  • Edit razor code for Razor Mediator TBBs
  • Synchronize *.cshtml files with Tridion TBBs
  • Debug *.cshtml files
  • Create Tridion_ Component Templates_ and_ Page Templates_ from Visual Studio automatically
  • Synchronize Visual Studio binaries (*.css, *.js, *.jpg, *.png, etc.) with Tridion multimedia components


  • Microsoft Visual Studio 2015 installed on a local machine
  • Tridion 2013 SP1 or SDL Web 8 with Razor Mediator 1.3.X installed on the local or remote machine


1. Run TridionVSRazorExtension.vsix

2. Create a new project based on RazorMediatorLayouts template

Your new project looks like next

In Tools menu you have the option Tridion Razor Extension

3. You can use the dialog window for adjusting VS / TCM mapping and running VS / TCM synchronization

4. You can use context menu on an item or a folder in Solution Explorer to run VS / TCM synchronization


* All mapping info is stored in TridionRazorMapping.xml file in the project root.

TCM mapping

Select folders on TCM side.

Every _Tridion _folder must have one of the following roles:

  • PageLayoutContainer. Folder that contains Razor Mediator TBBs for page layouts.
  • ComponentLayoutContainer. Folder that contains Razor Mediator TBBs for components.
  • PageTemplateContainer. Folder that contains Page Templates.
  • ComponentTemplateContainer. Folder that contains Component Templates.
  • MultimediaComponentContainer. Folder that contains Multimedia Components.
  • Other. No synchronization actions defined for this folder.

By default synchronization works only in VS -> TCM direction. To enable two-way synchronization, please use Two-way checkbox.

* TCM -> VS synchronization is more time-consuming, since TCM folders are scanned for new items.

Visual Studio mapping

Select folders from Visual Studio MVC project.

Use double-clicks to edit existing folder settings or the “Add” button to add a new folder.

In this dialog you can change the folder and file settings. 1. Role. Select project folder role:

  • PageLayout. Folder contains *.cshtml files for page templates.
  • ComponentLayout. Folder contains *.cshtml files for component templates.
  • Binary. Folder contains binaries (*.jpg, *.png, *.js, *.css, etc)
  • Other. Folder action is not defined.

If the files of different purposes are mixed in the same folder on the file system you can map this folder twice and select only the files of the specific type. All the checked files inherit role from the parent folder.

2. Template. Whether to create the page or component template after *.cshtml file was synchronized to Razor TBB. (Only PageLayout and ComponentLayout roles)

3. Tridion Folder. If you have more than one Tridion folder you can select which folder to synchronize.

4. Template Format. Piece of XML that is used to create Compound Component Templates from Razor TBB. All the checked files inherit role from parent folder.

5. Schema Names. List of schema names to link to Component Compound Template on creating.


You can run synchronization in three ways:

1. Dialog window – “Run Synchronization”.

Runs synchronization for all the mapped Tridion and project folders.

  • Item exists only in project. The user will be prompted to enter the name of a new Tridion item and select the target publication

  • Item exists only in Tridion (two-way must be enabled for Tridion folder(s))

User will be prompted to enter the name of a new project item and select the project folder to place it.

  • Item exists in both project and Tridion. The application compares dates and suggests the user which version to use.

* It is important to select the proper time zone to have the proper time comparison

The user can make a decision which version to use

* You won’t lose your previous changes. If you synchronize a Tridion item from the project then the new Tridion item version will be created, and you will be able to roll it back in TCM. If your project item is overwritten by a Tridion item then you can use your version control system to roll it back

2. Context menu on file(s) or folder

This kind of synchronization will synchronize only selected items.

Creating of component templates

If *.cshtml file was created in Visual Studio, and you want to create component template automatically, please use the next mapping settings:

After synchronization is run, you will have template created automatically


Before start debugging you need to set configuration for TcmDebugger. Please read Debugging Razor Mediator templates

You can start debugging synchronization in two ways:

  • From item context menu

  • Press Run from Visual Studio toolbar. Then the latest **.cshtml** will be run

If razor TBB was not debugged before you will be requested to set test component / page and test template that includes current layout

You can use breakpoints

Work with razor helpers

Application analyses Tridion.ContentManager.config and finds helpers on the file systemand makes a copy file in Visual Studio project:

To use this helper methods in other .cshtml files we need a customized version of Razor Generator

Make sure that helper file is marked with custom tool RazorGenerator

Also make sure that razor file has the next directive on the top. This is a marker that proper code generation is used

Then you will see file RazorHelpers.generated.cs with the next generated C# code

Since this code is included into base WrappedTridionRazorTemplate class it can be used in any razor file

* If helpers are located in standalone TBB instead of file system and referenced via import directive

Just set custom tool RazorGenerator for helper TBB