C# 如何使用RazorEngine包含文件?

C# 如何使用RazorEngine包含文件?,c#,razorengine,C#,Razorengine,我试图使用RazorEngine在模板中包含其他文件,但我有点卡住了。我已经掌握了基本知识,但我希望能够在模板中使用@Include(“somefile.html”) 这是我到目前为止得到的: string tpl = @"@Include(""foo.html"");"; ResolvePathTemplateManager r = new ResolvePathTemplateManager(new string[] { "html" }); var config = new Templa

我试图使用RazorEngine在模板中包含其他文件,但我有点卡住了。我已经掌握了基本知识,但我希望能够在模板中使用
@Include(“somefile.html”)

这是我到目前为止得到的:

string tpl = @"@Include(""foo.html"");";

ResolvePathTemplateManager r = new ResolvePathTemplateManager(new string[] { "html" });
var config = new TemplateServiceConfiguration();
config.TemplateManager = r;
var service = RazorEngineService.Create(config);

var a = service.RunCompile(tpl, "name", null, new { test = "TEMPLATE" });
当前工作目录有一个
html
dir,其中
foo.html
位于该目录下,但我收到以下错误:

无法解析模板名称


显然,在解析路径时,不能使用字符串模板。此代码适用于:

ResolvePathTemplateManager r = new ResolvePathTemplateManager(new string[] { "html" });
var config = new TemplateServiceConfiguration();
config.TemplateManager = r;
var service = RazorEngineService.Create(config);

var a = service.RunCompile("foo.html");
foo.html
中,我可以使用:

@Include("otherfile.html");

要包含来自同一目录的文件。

FWIW,我们使用一个
DelegateTemplateManager
,它允许您传递一个函数,该函数采用单个
字符串
参数,而不是
ResolvePathTemplateManager
。在该函数中,您可以执行任何您想要解析模板的操作-我们有一个搜索路径数组等。无论这是否适用于字符串模板。。。