toddams / RazorLight

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

Official sample doesn't work in .Net core 2.2 and Azure function SDK v2 #374

Closed rchaser closed 3 years ago

rchaser commented 3 years ago

Describe the bug This simple sample doesn't work

var engine = new RazorLightEngineBuilder()
    // required to have a default RazorLightProject type,
    // but not required to create a template from string.
    .UseEmbeddedResourcesProject(typeof(Program))
    .UseMemoryCachingProvider()
    .Build();

string template = "Hello, @Model.Name. Welcome to RazorLight repository";
ViewModel model = new ViewModel {Name = "John Doe"};

string result = await engine.CompileRenderStringAsync("templateKey", template, model);

System.Private.CoreLib: Exception while executing function: Function1. RazorLight: Can't load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file.

But it's set

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
    <PreserveCompilationContext>true</PreserveCompilationContext>
  </PropertyGroup>

To Reproduce Repo with the simplest code https://github.com/rchaser/RazorLightAndBlob

Expected behavior The sample should work

Information (please complete the following information):

jzabroski commented 3 years ago

I think you should avoid v2 AzureFunctionsVersion. It transitively uses .NET Core 2.2, which was end-of-life in December 2019. See: https://dotnet.microsoft.com/platform/support/policy/dotnet-core and https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions

At any rate, I don't think I can support this older version. I'm mainly just one person right now with a few people in the community pitching in. Sorry, I'm sure this stinks as an answer, but it's simply a matter of priorities.