razorengine - 运行 没有编译成动态程序集

razorengine - run without compiling into dynamic assembly

在以前的版本中,可以使用 Parse() 来完成这项工作。

请参阅 https://razorengine.codeplex.com/

中的旧文档
string template = "Hello @Model.Name! Welcome to Razor!";
string result = Razor.Parse(template, new { Name = "World" });

性感。但是现在只有 运行() 和 运行Compile()。为了使 运行() 工作,模板需要已经编译 - 我不能只传入模板名称。

因为我确实有几乎没有重复使用的剃刀模板,所以我希望能够不必将这些模板编译成动态程序集并将它们加载到应用域。临时文件问题是另一个原因。

这仍然可以使用 RazorEngine 吗?

NOT have to compile those templates into dynamic assemblies

Is this still possible using RazorEngine?

没有,而且从来没有。 Parse 将像 RunCompile 一样编译模板、加载和执行它。更糟糕的是,Parse 不缓存模板,因此加载的程序集甚至无法访问(=内存泄漏)

I cannot pass in the template only the template's name

如果将 using RazorEngine.Templating 添加到文件顶部,则可以通过扩展方法。您可以使用快速入门的“RunCompile”示例之一:https://github.com/Antaris/RazorEngine#quickstart

I do have razor templates where nearly no re-use is happening

您应该查看一下隔离 API 并时常重启隔离的 AppDomain。另一方面(如果你不想支付 AppDomain 边界的费用)你可以自己处理 AppDomain 重启并使用常规 API.

希望这对您有所帮助,

matthid(披露:RazorEngine 贡献者)