These are chat archives for Antaris/RazorEngine

14th
Apr 2015
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 09:21
Hi forks

I'm using RazorEngine v2 but run into issue with @Include.

string helloWorldTemplate = "Hello @Model";
Razor.CompileWithAnonymous(helloWorldTemplate, "helloWorld");

string fullTemplate = "@Include(\"helloWorld\", @Model.Name)! Welcome to Razor!";
string result = Razor.Parse(fullTemplate, new { Name = "World" });

I expected “Hello World” but get "Hello RazorEngine.Compilation.RazorDynamicObject".

Anyone can help?

Matthias Dittrich
@matthid
Apr 14 2015 09:52
That looks like a bug, I'll look into it.
I get the expected Hello World. Can you update to the latest version?
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 09:58
some dll we use is linked to v2. I'll try to upgrade to v3 with binding directions. Is v3 fully compatible with v2?
Matthias Dittrich
@matthid
Apr 14 2015 10:01
No not really, it's possible that you need to recompile that dll. However you should give it a shot as the legacy API is still there and working.
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 10:03
OK, thx
BTW, the dll is RazorEngine.dll, Version=2.1.4039.23635. That's from a legacy project so I don't know when and where it get the dll from.
Matthias Dittrich
@matthid
Apr 14 2015 10:07
And if you encounter an issue write it here as we may be able to fix it.
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 10:08
cool, thx
Matthias Dittrich
@matthid
Apr 14 2015 10:08
I don't know the version you mentioned, as I started maintaining the project on version 3.4 :)
So maybe they used the same version as Razor.dll back then
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 10:09
yes it's pretty old, at least 3 years I believe. I'm trying to upgrade to version 3.x. Hope nothing breaks. :)
Matthias Dittrich
@matthid
Apr 14 2015 10:10
So this is still net40, right?
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 10:10
yes, .net 4.0.
Matthias Dittrich
@matthid
Apr 14 2015 10:11
Good luck
Matthias Dittrich
@matthid
Apr 14 2015 10:18
Microsoft stopped supporting net40 and Razor3 is only build for net45. But we actually still support net40 by referencing Razor2 on the net40 build. So make sure you reference the correct .dll (nuget should take care of this). Just note that there are some bugs on the Razor parser which will never get fixed (there are some unit tests within RazorEngines test suite)... And the two builds are not compatible with the other Razor version. So for example if you are a library and reference RazorEngines net40 build and your caller redirects Razor2 to Razor3 everything will fail miserably (The same is true the other way around, which shouldn't happen in practice) ...
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 10:19
well, just found the lastest RazorEngine.dll has the different publicKeyToken from the legacy one we're using. It looks that I need to recompile RazorEngine by ourselves.
Yes, I've tried RazorEngine 3.6.5.0 in a .net 4.0 console, and it works fine. It's using System.Web.Razor.dll instead of Microsoft.AspNet.Razor.dll.
Matthias Dittrich
@matthid
Apr 14 2015 10:21
Microsoft.AspNet.Razor.dll is Razor4 if I'm not mistaken
which I guess will bring additional headache :(
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 10:23
I'm not very clear about that. I'm playing RazorEngine 3.6.5.0 in an .net 4.0 console project. After compiling it has only System.Web.Razor.dll in bin folder so I think Microsoft.AspNet.Razor is not required.
Anyway, let me try to download the source code of RazorEngine v2 and v3, then compiling v3 with v2's key.
Matthias Dittrich
@matthid
Apr 14 2015 10:24
Yeah those two are the same thing https://www.nuget.org/packages/Microsoft.AspNet.Razor/ pre 4.0 versions call their dll System.Web.Razor.dll and >4.0 versions Microsoft.AspNet.Razor.dll for whatever reason
I don't know why the key changed, sorry
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 14:18
I can only find the source code of v3.6.4 from github, but in NuGet it's already v3.6.5. Where can I get the the source of lastest version?
Matthias Dittrich
@matthid
Apr 14 2015 14:20
Ups I did forget to push the tags, they are now available.
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 14:22
Hi Matt, nice to see to online. I've compiled the the v3.6.4 source code with strong signing key of v2.1 and so far so good (with binding redirection, of course).
one thing is, when building RazorEngine by build.bat, the test project would fail to compile
Matthias Dittrich
@matthid
Apr 14 2015 14:24
What error do you see?
Matthias Dittrich
@matthid
Apr 14 2015 14:29
Ah, maybe because you changed the signing key, and we use the InternalVisibleTo attribute for testing?
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 14:32
Oh, it should be the reason.
Matthias Dittrich
@matthid
Apr 14 2015 14:34
You can probably get away with only changing the key of RazorEngine.Core...
Jeffrey Zhao
@JeffreyZhao
Apr 14 2015 14:37
yes, that could probability solve the issue.
but I need the core dll only so it's enough for me now.