Using the awesome 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!
Also, just running RazorLight from within LinqPad without referencing a classLib throws the same error. So below I've replicated this. Have tried official and unofficial versions of RazorLight, all throw same error.
Is there any way of getting around this error?
View: hello_world.cshtml
"Hello, @Model.Name. Welcome to RazorLight repository"
LinqPad: RazorLightTest.linq
<Query Kind="Program">
<NuGetReference Version="2.0.0-beta9">RazorLight</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