SDL Tridion Visual Studio Razor Extension is a VSIX extension for Microsoft Visual Studio that makes possible to work with Razor Mediator code.
Main functionality
- 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
Prerequisites
- Microsoft Visual Studio 2015
- SDL Tridion 2013 SP1 or SDL Web 8 with Razor Mediator 1.3.X
Downloads
https://drive.google.com/folderview?id=0B6hZ-cambftrV25ZLU5QTnJWSmM&usp=sharing#list
Source Code
https://github.com/mvlasenko/TridionVSRazorExtension
Installation
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 file or folder in Solution Explorer to run VS / TCM synchronization
Mapping
* 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.
By default synchronization works only in VS -> TCM direction. To enable two-way synchronization, please use Two-way checkbox.
Visual Studio mapping
Select folders from Visual Studio project.
Synchronization
You can run synchronization in two 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.
Automatic creating of component templates
If *.cshtml file was created in Visual Studio, and you want to create component template automatically, please use the next Visual Studio mapping settings:
After synchronization is run, you will have template created automatically
Debugging
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
Extension makes analysis of Tridion.ContentManager.config and finds helpers on the file system and makes a copy file in Visual Studio project:
To use this helper methods 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