English 中文(简体)
从一个档案中标出的自动标识和网络标识
原标题:Generate Razor and Webforms markup from one file

在我们的项目中,我们 st倒了以下问题:我们需要为我们的发展者提供两种主页(基于Razor和基于网络的网页),每个网页将产生实际上相同的超文本产出

我们的初步想法是使用T4级排气发动机,只使用一个模板,其中将分2个文档:*.master/code>和*.cshtml。 如@using Razor指令将对应<%@ Import. webforms statement。

关键的想法是,超文本部分应重复。 很显然,我们不能使用所建议的方法。 https://stackoverflow.com/questions/4746161/how-to-use-t4-to-generate-2-files-at-the-same-time- from-one-template” 如何利用T4同时从一个模板中生成两个档案? 由于这种情况的所有静态内容(请上层)都将重复。

显然,我可以撰写我的定制T4发电机,但会很复杂,因为有太多的指示(如<代码><%=“,即与Razor的@>相对应)。

关于我如何利用任何可用的排污发动机来做到这一点的任何其他想法?

最佳回答

After some brainstorming custom templates ( http://www.olegsych.com/2008/09/t4-tutorial-creating-reusable-code-generation-templates/ ) did the trick.

该设想有两个模板:一个模板,用于保持超文本和有条件的提交逻辑,另一个模板,用于头两次使用不同的参数。

A template-runner may look like the following:

<#@ include file="GenericMasterPageTemplate.tt" #>
<#
GenericMasterPageTemplate genericMasterPageTemplate = new  GenericMasterPageTemplate();
genericMasterPageTemplate._viewEngine = "Razor";
genericMasterPageTemplate.Output.File = @"PATH_TO_OUTPUT_RAZOR_TEMPLATE";
genericMasterPageTemplate.Render();

genericMasterPageTemplate._viewEngine = "Webforms";
genericMasterPageTemplate.Output.File = @"PATH_TO_OUTPUT_WEBFORMS_TEMPLATE";
genericMasterPageTemplate.Render();
#>

Obviously the conditional logic within the first template will analyze the value of _viewEngine parameter and render the necessary directives appropriately.

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签