Handlebars.Net icon indicating copy to clipboard operation
Handlebars.Net copied to clipboard

.NET Core 1 support

Open 206mph opened this issue 10 years ago • 37 comments

Any chance Handlebars.Net will support .Net Core in the very near future? Or, maybe it does and I'm just missing something.

206mph avatar May 17 '16 14:05 206mph

I haven't tested it on .Net Core yet, so I don't know how close or far it is from being compatible. I welcome any initial research to help move it along.

rexm avatar May 17 '16 18:05 rexm

I've been working on getting a version of this working on my machine. I've got most of the errors resolved but am stumbling on one error that I just am not familiar with and is occurring in several files. For example, in Compiler > Translation > Expression > BlockHelperFunctionBinder.cs, there are a couple lines of code that read helper.Method. This is throwing an error because there is no definition for 'Method' and no extension method for 'Method'.

It appears this is coming from System.Delegate in the current version. That's just my guess as some of this is a little beyond what this kind of work I do in C#. Any info would be great on where it's coming from or what it does. If I get that issue resolved, I will be down to 1 bug before I can compile/test.

206mph avatar May 17 '16 21:05 206mph

I believe there are some changes to how Core handles reflection

Sent from my iPhone

On May 17, 2016, at 17:50, Jason Johnson [email protected] wrote:

I've been working on getting a version of this working on my machine. I've got most of the errors resolved but am stumbling on one error that I just am not familiar with and is occurring in several files. For example, in Compiler > Translation > Expression > BlockHelperFunctionBinder.cs, there are a couple lines of code that read helper.Method. This is throwing an error because there is no definition for 'Method' and no extension method for 'Method'.

It appears this is coming from System.Delegate in the current version. That's just my guess as some of this is a little beyond what this kind of work I do in C#. Any info would be great on where it's coming from or what it does. If I get that issue resolved, I will be down to 1 bug before I can compile/test.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

rexm avatar May 17 '16 22:05 rexm

Hi,

Indeed, there are some changes in the .net core reflection but it's basically the same as it was with portable libraries.

I opened a pull request supporting netstandard 1.5 (I think it's possible to actually target a lower standard, I'll do some tests later). It also targets net451 (so the dotnet pack command generates a package fully compatible with any .net core app). I should also help supporting uwp.

I chose to reference existing source code instead of duplicating it. I had to add netstandard compilation variable. I think this should not create too much maintainability issue.

Looking forward to your feedback on how to improve it and make it mergeable :). Great work btw, I was using mustache-sharp so far and I love the "true handlebars" approach.

sandorfr avatar May 22 '16 18:05 sandorfr

Awesome start. Made a quick pass through this morning; will review in more detail this evening, but looks pretty straightforward.

I didn't see an update to the nuspec to target the correct framework - is that an oversight?

rexm avatar May 23 '16 13:05 rexm

Your're right I did not update the nuspec. I'll look into this tonight.

However, since project.json acts as a sort of nuspec file, you can generate one easily running dotnet pack -c Release --version-suffix dotnet-core-rc2-0001 in the project.json directory. (I have a packaged one available there : https://www.myget.org/feed/sandor-public/package/nuget/Handlebars.NetStandard)

sandorfr avatar May 23 '16 14:05 sandorfr

Just updated the nuspec file. I think you should not merge it to your master branch until dotnet core is RTM and publish those packages with a prerelease tag until then (just my 2 cents).

I also did some searches about nunit tests with .net core it seems it's not quite there but coming (https://github.com/nunit/nunit/issues/1371).

sandorfr avatar May 23 '16 20:05 sandorfr

Worth noting that a side effect of netstandard is that windows 10 is supported (#102)

sandorfr avatar May 23 '16 20:05 sandorfr

.net core RTM preview package available here : https://www.nuget.org/packages/Handlebars.NetStandard/1.0.0-dotnet-core-rtm1

sandorfr avatar Jul 05 '16 11:07 sandorfr

@sandorfr excuse me, does it still depends on Framework 4.5 anyway? nuget.org shows old .NET in the dependency list.

EvilBeaver avatar Nov 24 '16 17:11 EvilBeaver

Sorry, I should have closed this issue. The official release does now support dotnet core and .NET 4.x. Both versions are in the same package.

rexm avatar Nov 24 '16 18:11 rexm

Can someone point me in the right direction for using Handlebars.Net as the view engine for Asp.Net core?

I'm coming from node.js development and I'm having a hard time understanding how to use Handlebars.net instead of the default Razor view engine.

priedthirdeye avatar Jan 12 '17 02:01 priedthirdeye

The Handlebars library doesn't have turnkey support for ASP.NET view engines. It requires some framework-level work on your part to get it all working.

rexm avatar Jan 12 '17 04:01 rexm

@priedthirdeye

Just my two cents, but as much as I love handlebars, I would advise against using it as your view engine.

  • it's far less powerful as Razor (think about tag helpers for instance)
  • you will be likely to be very isolated in your scenario, hence won't have community / microsoft support
  • you will add a learning curve for any already asp.net fluent developer
  • you will be on the bleeding edge

Kind regards.

sandorfr avatar Jan 12 '17 10:01 sandorfr

So when Handlebars.Net was branched to "support .net core", was that not related to using it as a view engine for asp.net core?

Please note that I'm new to this technology, so my terminology and understanding may be off.


I have a use case where it may make sense to use handlebars as the view engine. I at least want to consider it before presenting options to my boss.

Some Details:

We currently have a website that has several thousand templates using a custom template language very similar to handlebars. The architecture, written in c++ many years ago, passes input to stored procedures and prepares the results as variables and/or loops for the use in the templates. Employees, many of which are not "developers", are familiar with the template language and very basic logic structure. It is by design that we have a relatively limited amount of functionality at the template level. The owner wanted templates to be easy to understand for someone with basic HTML knowlege and basic training. Since I'm presenting alternatives to our existing system, I'd like to try to stay as close to his vision as possible. In my current direction using .NET core, I won't be using the "M" in the "MVC" architecture. I just want to create something that can execute our existing stored procedures, and make the variables and loop data available to the handlebars template. I understand that I will lose out on a lot of benefits of .net core in doing it this way, but I get the impression from my preliminary review that true asp.net core MVC with the Razor view engine would likely add huge cost and time to the conversion effort and likely fuel a decision to just keep things the way they are. We are not building from the ground up.

I already created a pretty mature proof of concept using node.js, Express and Handlebars that does what I want. Right before I was preparing to present a proposal for new architecture I read an article on asp.net core being faster than node.js. That's why I'm trying to create asp.net core proof of concepts as well.

priedthirdeye avatar Jan 12 '17 12:01 priedthirdeye

The documentation for a custom view engine is just a placeholder:

https://docs.microsoft.com/en-us/aspnet/core/mvc/views/custom-view-engine

And it appears people aren't having much luck implementing a custom view engine:

https://github.com/aspnet/Docs/issues/137

priedthirdeye avatar Jan 12 '17 12:01 priedthirdeye

I didn't see the comment from @rexm when I responded with my question.

Thanks for your answers.

priedthirdeye avatar Jan 12 '17 12:01 priedthirdeye

You're right this is just support for .netstandard 1.5 which means that you can reference this library from a net core app.

Support as a view engine is another subject which could be brought as an additional library on top of this one.

sandorfr avatar Jan 12 '17 12:01 sandorfr

I agree with @sandorfr... Handlebars is likely a very good candidate for your use case with such a large set of templates, but I would recommend building something simpler and more specific to your exact use case on top of ASP.NET (or any mainstream framework/platform) instead of trying to repurpose the very sophisticated plumbing of the framework itself.

rexm avatar Jan 12 '17 13:01 rexm

Thanks. I now understand that using asp.net core MVC is overkill for what I am trying to accomplish. I'm now moving forward with a non-MVC asp.net core implementation.

Do you know of a boilerplate available for a .net core project that just utilizes .net core (no MVC), has routing and serving templates (ideally using Handlebars.net already)? I looked and couldn't find anything.

I just started a regular asp.net core application without MVC, added routing and I am now working on figuring out how to serve templates and ultimately utilize Handlebars.Net. I'm hoping there is a boilerplate that will get me further along from the start.

If you are not aware of a boilerplate like I describe perhaps just confirm that I'm heading in the right direction.

priedthirdeye avatar Jan 12 '17 17:01 priedthirdeye