I am using LinqPad which references a ClassLib which in turn executes the RazorLight engine. Physical cshtml files live in a local folder. I run into the same error:
RazorLight.RazorLightException: Can't load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file
I tried adding <PreserveCompilationContext> into the classlib csproj, though I know it will not work as it's not the entry point. LinqPad is the entry point!
Attached a simple test linqpad file in the Zip. Also the source code is shown below, just save it as XXX.linq.
hello_world.cshtml"Hello, @Model.Name. Welcome to RazorLight repository"
Linq file code:
<Query Kind="Program">
<NuGetReference Prerelease="true">RazorLight.Unofficial</NuGetReference>
<Namespace>RazorLight</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
void Main()
{
RazorLightTest().Dump("RazorLight output");
}
public async Task<string> RazorLightTest()
{
var engine = new RazorLightEngineBuilder()
.UseFileSystemProject(@"D:\Temp")
.UseMemoryCachingProvider()
.Build();
var model = new { Name = "John Doe" };
return await engine.CompileRenderAsync("hello_world.cshtml", model);
}
// You can define other methods, fields, classes and namespaces here
I am using LinqPad which references a ClassLib which in turn executes the RazorLight engine. Physical
cshtml
files live in a local folder. I run into the same error:RazorLight.RazorLightException: Can't load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file
I tried adding
<PreserveCompilationContext>
into the classlib csproj, though I know it will not work as it's not the entry point. LinqPad is the entry point!Attached a simple test linqpad file in the Zip. Also the source code is shown below, just save it as XXX.linq.
Is there any way of getting around this error?
razorlight_test.zip
hello_world.cshtml
"Hello, @Model.Name. Welcome to RazorLight repository"
Linq file code: