在.NET中使用的核心MVC剃刀外 [英] Using Razor outside of MVC in .NET Core
问题描述
我想用剃刀在我的.NET的核心正在写一个.NET控制台应用程序模板引擎。
I would like to use Razor as a templating engine in a .NET console application that I'm writing in .NET Core.
的独立剃刀引擎我已经遇到(RazorEngine,RazorTemplates)都需要完整的.NET。我在寻找与.NET核心的解决方案。
The standalone Razor engines I've come across (RazorEngine, RazorTemplates) all require full .NET. I'm looking for a solution that works with .NET Core.
推荐答案
最近,我创建了一个名为的剃刀光芒
Recently I've created a library called RazorLight.
它没有多余的依存关系,像ASP.NET MVC零件,并且可以在控制台应用程序中使用。 。目前它只支持.NET的核心(NetStandard1.6) - 但是这正是你需要的。
It has no redundant dependencies, like ASP.NET MVC parts and can be used in console applications. For now it only supports .NET Core (NetStandard1.6) - but that's exactly what you need.
下面是一个简单的例子:
Here is a short example:
string content = "Hello @Model.Name";
string result = new RazorLightEngine().ParseString(content, new { Name = "John" });
这篇关于在.NET中使用的核心MVC剃刀外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!