You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm looking for a Razor templating solution which could work with AoT compilation in .net 7, with <PublishAot>true</PublishAot>.
When visiting http://localhost:5000 the following example correctly returns text/html and the rendered view if starting with debugging (without AoT). But after publishing with AoT it returns application/json and emty json {} in the browser.
using Razor.Templating.Core;
namespace AotTest1;
public class ExampleModel
{
public string PlainText { get; set; }
public string HtmlContent { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapGet("/", HandleRequest);
app.Run();
}
private static async Task<IResult> HandleRequest(HttpRequest request, HttpResponse response)
{
var model = new ExampleModel()
{
PlainText = "This text is rendered from Razor Views using Razor.Templating.Core",
HtmlContent = "<em>You can use it to generate email content, report generation and so on</em>"
};
var html = await RazorTemplateEngine.RenderAsync("/Views/ExampleView.cshtml", model, viewDataOrViewBag);
return Results.Text(html, "text/html");
}
}
Hi @kurtcodemander, thanks for raising the issue. Although I wish that I could add support for NativeAOT, the underlying ASP.NET Core MVC itself needs support for it. Only then, it will be possible for our library to add support as it's a wrapper around the MVC. As of .NET 7 timeframe, we could see that the NativeAOT is mainly focused on console applications. So let's hope that MVC will be supported in the near future and we'll make our library support it too :)
Thanks @soundaranbu, I found a great micro-framework by David Fowler which is AOT friendly and suits my needs for now as a workaround. Although it doesn't support Razor.
I'm looking for a Razor templating solution which could work with AoT compilation in .net 7, with
<PublishAot>true</PublishAot>
.When visiting http://localhost:5000 the following example correctly returns text/html and the rendered view if starting with debugging (without AoT). But after publishing with AoT it returns application/json and emty json {} in the browser.
Why? Is it possible to make it work with AoT?
The text was updated successfully, but these errors were encountered: