Wya*_*att 9 .net asp.net asp.net-mvc templates latex
是否可以使用asp模板引擎(使用部分代码隐藏类,动态<%...%>块等)来生成非HTML?我希望有一种干净且可维护的方式来动态生成代码.(具体来说,我想生成使用数据库中的值填充的LaTeX代码.)
目前,我的LaTeX模板是带有占位符的资源字符串,我使用数据库值进行字符串替换.这种解决方案很快变得非常难以维护和清洁.我真的很想使用来自aspx标记的动态块,但是我不确定a)当输出不是HTML时,aspx是否会抛出拟合,或者b)如何将结果实际呈现为.tex文件.
生成代码本身位于C#.dll中.我们使用的是.NET 3.5
这可能吗?提前致谢.
Visual Studio 2008本身或使用Visual Studio 2005 SDK附带的T4模板,您几乎可以生成任何您想要的内容.
您可以在以下链接中获得更多信息:
我很确定所有这些链接都是您开展任务的良好开端.
如果要在Visual Studio外部生成T4模板,可以使用自定义MSBuild任务来调用T4模板(链接)
以下是MSBuild任务的"执行"代码示例.点击这里获取源代码:
public override bool Execute()
{
bool success = false;
//read in the template:
string template = File.ReadAllText(this.TemplatePath);
//replace tags with property and item group values:
ProjectHelper helper = new ProjectHelper(this);
template = helper.ResolveProjectItems(template);
//copy the template to a temp file:
this._tempFilePath = Path.GetTempFileName();
File.WriteAllText(this._tempFilePath, template);
//shell out to the exe:
ProcessHelper.Run(this, TextTransform.ToolPath, TextTransform.ExeName, string.Format(TextTransform.ArgumentFormat, this.OutputPath, this._tempFilePath));
success = true;
return success;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1501 次 |
| 最近记录: |