Closed genifycom closed 6 years ago
Thanks for contacting us, @genifycom. @NTaylorMullen, do we have an updated sample somewhere, which we can point customers to?
@genifycom the latest RazorPageGenerator is 2.1 (Razor without MVC).
Also our samples repo has a "render view to string" example using MVC.
Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.
The sample you indicated requires MVC but I am looking for a console app that does not require a webserver. A sample usage would be if you create an AWS Lambda Function (i.e. a single entry point with no routing). So one calls this one function and Razor returns the string generated from template.
If you include MVC, then you have to support the whole hosting environment which is not needed.
So is Razor supported without MVC?
Parsing files in Razor without MVC is what my RazorPageGenerator link above accomplishes. If you're looking to render the contents of that page to a string, then you'll be responsible for providing the types referenced in the generated code that MVC usually provides.
Also to respond to
If you include MVC, then you have to support the whole hosting environment which is not needed.
You should be able to get most of the away with using the MVC types from Microsoft.AspNetCore.Mvc.Razor
(doesn't depend on hosting).
NTaylorMullen So I have it generating the designer files. But I can't seem to satisfy references in the generated files. For example:
Microsoft.Extensions.RazorViews.BaseView (looks like this changed).
I have Microsoft.AspNetCore.Mvc.Razor included.
Any tips?
When using Roslyn to compile your Razor files I'd recommend using DependencyContext to capture your apps current set of references to allow for view compilation.
Oh I need this for the compiled files right?
https://dotnet.myget.org/feed/aspnetcore-dev/package/nuget/Microsoft.Extensions.RazorViews.Sources
You don't need to have them. You can create those types for yourself if you want.
I cannot seem to find anything on how to implement Razor in a C# Console App for .NET Core 2.1
Compilation indicates "'RazorEngine.Create(Action)' is obsolete" and "The recommended alternative is RazorProjectEngine.Create".
In addition previous 2.0 examples no longer work.
Please can we have a working sample of using the Razor engine using .NET Core 2.1 in a C# Console app.