Version 1.2 emits RazorGenerator.Templating.RazorTemplateBase

Sep 1, 2011 at 5:40 PM

After upgrading from 1.1.2 to 1.2 templates strated generate class with base RazorGenerator.Templating.RazorTemplateBase. In 1.1.2 there were nice generators that had not require any references. Any idea how to return 1.1.2 behaviour as it's much more usable?

Coordinator
Sep 1, 2011 at 5:48 PM

In 1.2, you need to install the RazorGenerator.Templating NuGet package into the project. With the new layout features, the base class was starting to get big, and it didn't make sense to have it replicated in every template. RazorGenerator.Templating.dll is just a harmless little 6KB binary :)

Sep 1, 2011 at 6:00 PM

Ok, thanks.

P.S. May be there could be and option?

Coordinator
Sep 1, 2011 at 6:17 PM

Conceivably there could be. But can you explain why you see importing this DLL as an issue? Most other things require some kind of runtime, so this feels pretty 'standard' :)

Coordinator
Sep 1, 2011 at 7:00 PM

Turns out there is already a very simple way to do this if you don't want the assembly reference:

  1. Define your own base class in your own assembly (you can copy the one from RazorGenerator.Templating.dll is you like
  2. Add '@inherits CustomTemplateBase' in your cshtml to say you want to use your base.

So your cshtml will start with something like this:

@* Generator: Template *@
@inherits CustomTemplateBase
Can you please give this a try?

Sep 23, 2011 at 1:26 AM

Hi David, 

I agree with chaliy, it would be nice if there was another optional directive that emits the base template automatically.  It was less fuss, and it "just worked".  Now there's more hassle to get going.  I think an option would make your extension more accessible to newcomers.

That being said, your suggestion to use @inherits worked like a charm, and solves my problem nicely, especially since I wanted to use a custom base type anyway to add common properties across multiple templates.

Thanks for your hard work in providing this extension, I swear by it now and use it for all sorts of problems.  

Coordinator
Sep 23, 2011 at 2:09 AM

Thanks for the feedback @kswoll! Maybe one thing we could do is offer a standard base class as a simple NuGet package that just brings in a source file (not a DLL). This way it can be used as a starting point.

Sep 24, 2011 at 5:08 PM

How about a seperate Generator directive that generates the base class as an object?  Then it would only need to be generated once, when needed, on demand.  In our build environment, I need to have the dll installed several places for all the development, testing, deployment to work.  When it is include within the project dll, I don't have those change control issues.

Coordinator
Sep 24, 2011 at 5:35 PM

@msauper: what do you mean by 'generates the base class as an object'? Are you talking about generating a binary (which the package already covers) or generating source code?

Sep 24, 2011 at 5:56 PM
Edited Sep 24, 2011 at 6:09 PM

I'm thinking of a directive that would generate the base-class inline.  A one-line file such as:

RazorBaseclass.cshtml:

@* Generator: Baseclass *@

This would generate a file RazorBaseclass.generated.cs which contains the definition of the razor base class that would be compiled into the project dll.

It would have the benefit of only generating the baseclass code once per project.  In addition, programmers that preferred to use the nuget added dll would still be able to do so and would not need to create this file.

Coordinator
Sep 25, 2011 at 5:41 AM

Seems a bit quirky to use a cshtml just to generate this class, as the cshtml would not have real content. It also wouldn't be customizable. Probably makes more sense to make the base code available as a nuget source package as I mentioned above.

But in any case, the workaround for now is pretty simple: just copy this class into your project and you're good to go!