Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.14k stars 578 forks source link

.NET CORE support? #551

Open PeterOeClausen opened 5 years ago

PeterOeClausen commented 5 years ago

Is the framework supported in .NET CORE? If not, is there a plan to support it later? :-)

fourhundredfour commented 5 years ago

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.razor.language

I think it is supported in .NET Core.

PeterOeClausen commented 5 years ago

I'm getting an exception when running Engine.Razor.RunCompile:

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
  Source=RazorEngine
  StackTrace:
   at RazorEngine.Compilation.CSharp.CSharpDirectCompilerService..ctor(Boolean strictMode, Func`1 markupParserFactory)
   at RazorEngine.Compilation.DefaultCompilerServiceFactory.CreateCompilerService(Language language)
   at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
   at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEmailTemplateLibrary.Class1.Compile() in C:\Users\pc\Documents\GitRepositories\VisualStudioSolution\RazorEmailTemplateLibrary\Class1.cs:line 25
   at IOTWeb.Controllers.EmailController.SendEmail() in C:\Users\pc\Documents\GitRepositories\VisualStudioSolution\IOTWeb\Controllers\EmailController.cs:line 46
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()

I've also tried installing the Microsoft.AspNet.Mvc NuGet package.

Do I need to configure RazorEngine somehow?

didii commented 5 years ago

Pete, you're getting a more generic error message. Can you check in your references if System.Web.Razor is actually listed (without an exclamation mark)? In any case, try (re)installing the package Microsoft.AspNet.Razor which should contain the needed dll. Source: https://stackoverflow.com/a/48079486/2158015 (please don't do the accepted/first answer)

GMihalkow commented 5 years ago

Did you find a solution for this problem?

PeterOeClausen commented 5 years ago

@GiMihalkow Nope. I ended up using a forked version of RazorEngine, that's names something like "RazorEngine.NetCore", but it had a lot of issues and unsupported features.. Can't recommend it.. Now I'm not working on the project any longer, and hence I don't need it. But I never made it work with RazorEngine.

@didii Tried it didn't work. I don't know if it was just me getting the issue, or if this is a general thing for using NetCore and RazorEngine...

One can check it easily, by creating a new console NetCore solution, download the RazorEngine NuGet package, and try to compile something... I may try it very soon. If it works, I'll comment and close this issue.