toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 260 forks source link

.NET Core 2.0 status #63

Closed toddams closed 6 years ago

toddams commented 7 years ago

Microsoft has rolled out .NET Core 2.0-preview1 and I thought that it's a good time to start 2.0 version of RazorLight. But today got an email from Razor repo about another refactoring / breaking changes, like this one: https://github.com/aspnet/Announcements/issues/242 . That makes things a little bit more complicated, as I don't know whether Microsoft guys will not do yet another breaking change before stable release. So I created this issue in order to let you know about the status of the development.

We are waiting for stable release and right after that 2.0 will start it's development.

danwalmsley commented 7 years ago

Is development likely to start soon? On my project I'm holding up a release for this and don't want to have to find an alternative to razorlight being that it works so well. The apis should be fairly stable now.?

toddams commented 7 years ago

Hello @danwalmsley I understand your situation and indeed we need to start development already, to at least have some base functionality, even though 2.0 is still in preview. I hope there won't be any major breaking changes

dukecheng commented 7 years ago

Hi @toddams

As the 2.0 preview 2 already released one month after, and RTM will be on 9.18, do you have any plan to release a preview version for the RazorLight? that can let us use for now?

toddams commented 7 years ago

@DukeCheng At the moment I'm in a process of development, the thing is that there were a lot of changes, and for me it's kinda making everything from scratch. Lack of time and other factors are the main reason why it's not yet ready. But no doubts, I will try to deliver a new version asap

kspearrin commented 7 years ago

We too need this for NET Core 2.0. We are still using ASP.NET Core 1.1.2, but have updated to netcoreapp2.0 to gain additional .NET Standard APIs. RazorLight seems to have issues with .NET Core 2.0 (even through still ASP.NET Core 1.1.2).

kspearrin commented 7 years ago

@toddams is it possible for you to push your WIP we we can see how things are changing?

kspearrin commented 7 years ago

.NET Core 2.0 has been released today. https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-core-2-0/

danwalmsley commented 7 years ago

bump!

toddams commented 7 years ago

I understand you guys, that you may need it in your projects, etc. So here I'm giving myself a deadline. First beta will be released in the middle-end of September.

kspearrin commented 7 years ago

Thanks for the update @toddams That helps with planning at least.

dukecheng commented 7 years ago

@toddams Thanks, we are expecting your first version.

MattMofDoom commented 7 years ago

Sweet! 👍

mechm commented 7 years ago

any update on this - i am getting System.TypeLoadException: 'Could not load type 'Microsoft.AspNetCore.Razor.RazorEngineHost' from assembly 'Microsoft.AspNetCore.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.' This works fine with 1.6 but not 2.0 .netcore.

grokky1 commented 7 years ago

Hey all... Also have problems now that I've upgraded to netcoreapp2.0. I was wondering whether it's possible to use some sort of workaround until the new version is released.

I remember reading somewhere that it's possible to reference .NET framework assemblies somehow. Maybe we can reference the current version of RazorLight from a netcoreapp2.0 assembly, and it'll work. Problem is I don't know how to get this working. Have any of you managed to do something like that???

(To be clear what I mean is to do something in our csproj. I don't mean changing anything in RazorLight itself)

The problem is here. Error is Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.

grokky1 commented 7 years ago

@kspearrin Have you found a workaround for now? Your comment seems to indicate that you managed to upgrade to 2.0 somehow?

kspearrin commented 7 years ago

No workaround. I moved to another alternative in the meantime. :(

grokky1 commented 7 years ago

@kspearrin I like RazorLight, and I want to carry on using it, but until the next version is released, would you mind letting me know what alternative there is? The only one I know of is Postal, but it hasn't been updated in years...

kspearrin commented 7 years ago

I switched to using a markdown implementation with https://github.com/Knagis/CommonMark.NET

Much more basic, but it works for me, for now.

see https://github.com/bitwarden/core/blob/master/src/Core/Services/Implementations/MarkdownMailService.cs

grokky1 commented 7 years ago

~@kspearrin Good idea! It is basic like you said, but a decent workaround until RazorLight is updated.~

Spoke to soon... I discovered after some fiddling that in my case it's too much effort / impossible to convert from Razor templates to markdown. I've gone back to Core 1.1 until this library is updated... 😢 Thanks for the advice though, it was worth a try!

chrisofe commented 7 years ago

Could really do with this! Any news on when a beta will be available?

andrew-blyth commented 7 years ago

+1 for an update ASAP

cdroulers commented 7 years ago

https://gist.github.com/cdroulers/9ed5b5b2e5c035a0e6912a88c7043f96

Here is my replacement since my use-case was very simple (render full page HTML with a few model variables, no layouts or anything). But since it uses the Framework Razor stuff, I think it would work with layouts and whatnot. While debugging, the framework was requesting the "_ViewImports.cshtml" file. I therefore assume that it would parse layouts and whatever!

grokky1 commented 7 years ago

@cdroulers Cool thanks for helping out! I'm gonna try this... That gist says your use case was embedded files. I only use RazerLight for rendering strings. Have you managed to use it that way?

cdroulers commented 7 years ago

@grokky1 Yes, the renderer simply creates a string like RazorLight. By embedded Files, I mean my .cshtml templates are simply embedded in the DLL instead of being on the file system (easier for deployment, less configuration for root path, etc.)

grokky1 commented 7 years ago

@cdroulers No what I mean is the inputs to RL - it supports 1) files, 2) embedded resources, and 3) strings. Your gist (from what I can udnerstand) uses embedded resources as inputs. Would that workaround somehow support string input as well?

Maybe @toddams can give us an idea how to make this workaround work for all 3 use cases...

cdroulers commented 7 years ago

Ohh, I get what you mean. I'm not a Razor expert, but I'm guessing you could create a "StringFileProvider" that simply returns the "fileName" it was passed, which would be your Razor Template. Change the ViewLocationFormats to "{0}" and I think you'll get the value straight away. Feels hacky, but would be appropriate for a temporary fix!

andrew-blyth commented 7 years ago

@cdroulers . Well done for publishing an alternative. We also use an embed file and it works for us..

dukecheng commented 7 years ago

@toddams Hi, Does any progress on this project and do you need contribution, if you needed, Please tell me, I also worked out a basic version that worked on .net core 2.0 based on lasted RazorLight master branch code.

wapplegate commented 7 years ago

@DukeCheng Is there any way you can release a temporary nuget package for the update you've done? Need to get something set up quick and I don't want to move away from using the RazorLight library.

toddams commented 7 years ago

Small update, so you don't think I'm dead or smth :) This night I managed to generate and compile first razor template using 2.0 version. Now I need to add features (like Includes, Layouts, Injects) /caching/unit-tests/etc.

As planned, in the middle of September I will release first beta with the same set of features as 1.0 version had, but with new Razor engine and NetStandard 2.0 support. TagHelpers and other sweets are postponed as there are too much MVC-specific stuff inside and I will take more time than I expected.

dukecheng commented 7 years ago

@toddams Wow, You are live, very happy to here you are still working on this.

dukecheng commented 7 years ago

@Singularity222

the temp code is here: https://github.com/dukecheng/razorlight2 and I still have many problems, currently stuck at model part, I am still investigate how to resolve it. now it just can complete a very simple signal page, not support layout yet.

This code is copy from CURRENT RAZORLIGHT code, it is just for study and learning, the copyright belong to @toddams

grokky1 commented 7 years ago

@toddams Very happy to hear that!

If you want guinea pigs to test on, many of us will be glad! 😄 You could release betas on myget and I'm sure all of us on this thread will give you feedback!

wapplegate commented 7 years ago

@toddams Is there any way you can deploy a beta nuget package with just the basic features working in .NET Core 2.0? I would be willing to make a donation to your project if so. I'm in a bit of a time crunch and would greatly appreciate it.

toddams commented 7 years ago

@Singularity222 I see. What features do you use in your templates?

wapplegate commented 7 years ago

Honestly, just the basic functionality is all I need at the moment. No layout files or anything like that. Right now I'm just pulling a very basic razor view from the database and using the ParseString method with a very simple model. That's all.

wapplegate commented 7 years ago

Also, if the performance is slow for the time being it's no issue. Won't be going to production for a while. Have internal deadlines though and don't want to duplicate my effort. I'd be willing to beta test / help with the project. I like using razor for templates and don't want to switch to something else.

johnknoop commented 7 years ago

@Singularity222 you could always clone https://github.com/dukecheng/razorlight2 and build it yourself. If you need it in several projects, just put it on a MyGet feed.

Scratch that, I just noticed that @toddams already has put it on NuGet :-)

wapplegate commented 7 years ago

I actually did try that and was running into issues rendering my templates when added to my project unfortunately. Just haven't had time to dig into it deeper yet.

pmpbpl commented 7 years ago

I have tired to use nuget package, but unfortunately there is version conflict for Microsoft.CodeAnalysis.Common.

Web app is targeting netcoreapp2.0.

*.Web (>= 1.0.0) -> *.Service (>= 1.0.0) -> Microsoft.CodeAnalysis.Common (>= 2.3.2) *.Web (>= 1.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Design (>= 2.0.0) -> Microsoft.VisualStudio.Web.CodeGenerators.Mvc (>= 2.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration (>= 2.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore (>= 2.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Core (>= 2.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Templating (>= 2.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Utils (>= 2.0.0) -> Microsoft.CodeAnalysis.CSharp.Workspaces (>= 2.3.1) -> Microsoft.CodeAnalysis.Workspaces.Common (>= 2.3.1) -> Microsoft.CodeAnalysis.Common (>= 2.3.1).

johnknoop commented 7 years ago

I'm also trying it out. It runs alright, but when parsing my Razor view, I get this:

The name 'Model' does not exist in the current context

...for a simple @Model.MyProperty expression.

csanctis commented 7 years ago

I am trying the new 2.0 version but and I am also getting the "The name 'Model' does not exist in the current context" message. And version 1 does not work as it cannot find the RazorEngine class for the parse.

pmpbpl commented 7 years ago

I have tired to use nuget package, but unfortunately there is version conflict for Microsoft.CodeAnalysis.Common.

Microsoft.AspNetCore.All 2.0.0 is setting Microsoft.CodeAnalysis.Common to version 2.3.1, when I specified version 2.3.2 build have succeeded.

Now I have same problem as @johnknoop and @csanctis.

toddams commented 7 years ago

On Sunday I will upload first aplha to MyGet with just basic razor.

toddams commented 7 years ago

Install-Package RazorLight -Version 2.0.0-alpha1

So first alpha is there. Please, keep in mind, that this package is only released because some people REALLY need it on their project, I don't recommend to use in your super-production. Here are quicknotes:

So what is implemented?

I've pushed the changes to dev-2.0 branch

I have created gitter channel - https://gitter.im/Razor-Light If you have super-urgent questions - feel free to ask

akabii commented 7 years ago

Nice one @toddams just tried it out. Works like charm. Really appreciate

        services.AddSingleton<IRazorLightEngine>(f =>
        {
            return (new EngineFactory())
                .ForFileSystem($"{Environment.ContentRootPath}\\Views");
        });

and then used like emailContent.Body = await _engine.CompileRenderAsync("Test.cshtml", model);

toddams commented 7 years ago

For those, who store templates in database, @DukeCheng provided very nice sample https://gist.github.com/toddams/8ebf21be9597ee48f47085b879b46ca7

toddams commented 6 years ago

Alpha2 is out with support of Includes and Raw.

Closing this issue, as primary goal is achieved. If you have any questions regarding an existing functionality - use gitter. In case of bug - open a new issue.

Information about new releases you can find at Releases section - https://github.com/toddams/RazorLight/releases