7

Using Visual Studio 2012 I am able to edit Razor TBBs by opening and saving them back via webdav. The problem is that if there is a Razor syntax error, it seems like they are saved OK, but actually they are not - there is no feedback of the error that you would normally get when saving them using the Tridion GUI. Is it possible to get Visual Studio to show this error, or (even better) get Visual Studio do the compilation/error checking that Tridion does before saving?

1
  • Saving any template type works like this, all the way back to VBScript. Saving via webdav seems to work (save) but if there is an error a new version is not created. I think you will have to look for a different approach than webdav to ever see error messages. Jul 31 '13 at 16:06
9

I developed Visual Studio 2010 Extension (might be working in 2012) for synchronization Visual Studio *.cshtml files with Tridion TBBs via CoreService

http://code.google.com/p/visual-studio-extension-4-tridion-razor-mediator/

The main idea how to make razor mediator files editable is next:

  1. Add next web.config to 'fake' ASP.NET MVC application

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="Tridion.Extensions.Mediators.Razor, Version=1.3.0.0, Culture=neutral, PublicKeyToken=5eeceedb34d9dfd7" />
            <add assembly="Tridion.Common, Version=6.1.0.25, Culture=neutral, PublicKeyToken=349a39f202fa9b53" />
            <add assembly="Tridion.ContentManager.Templating, Version=6.1.0.996, Culture=neutral, PublicKeyToken=360aac4d3354074b" />
          </assemblies>
        </compilation>
      </system.web>
    </configuration>
    
  2. Add declaration to the top of razor file

    @inherits Tridion.Extensions.Mediators.Razor.TridionRazorTemplate
    

Please read document for details https://drive.google.com/folderview?id=0B6hZ-cambftrV25ZLU5QTnJWSmM&usp=sharing#list

Mark

1
  • Thanks for sharing this. It's great. Would you consider putting the source into Source Control? Jan 4 '14 at 8:23
5

I like the idea of capturing the error in Visual Studio. One possible approach might be to execute the relevant mediator code in a build step or from a VS extension. I'd start with the Compile method at https://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Engine/Compiler.cs

You may be able to get this to work directly, but if not, I think it would be a great enhancement for the mediator if we could get it to support this approach. It's probably much easier if you are developing on the machine where Tridion is installed. To support off-the-box work, we might need some sort of service.

1
3

Here is in my blog explained how to debug Razor Mediator .cshtml files in Visual Studio.

http://mvlasenko.blogspot.com/2015/12/debugging-razor-mediator-templates.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.