CodeSmith 与 T4:.netTiers 级别套件
有人将 netTiers 模板集移植到 Visual Studio 的 T4 模板吗? 或者是否有类似范围的系统? 有人在工作环境中使用 T4 吗? Codesmith 和 T4 之间有什么(如果有)主要区别?
Has someone ported the netTiers template set to Visual Studio's T4 templates? Or is there a system of similar scope? Does anyone use T4 in a work environment? What (if any) major differences are there between Codesmith and T4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我稍微涉足了 T4 - 嘿,如果它是免费的并且包含在 VS2008 中,请使用它,对吧?
我的基本想法是创建一组模板来读取数据库表,并从中创建我们自己的“自己动手”ORM 类。
我放弃了 T4,感到沮丧,甚至连最基本的东西都无法工作,而这些东西在 CodeSmith 中简直就是小菜一碟。
即使是选择要使用的服务器、数据库和表等简单任务,也无法在 T4 中从模板本身的“外部”有效完成。 是的,您可以将所有这些值作为字符串值硬编码到 T4 模板中 - 但来吧,这确实不是一个解决方案,不是吗?
CodeSmith 对选择服务器、数据库和表有很好的支持,您可以将它们设置为模板上的属性,然后选择您想要的内容,然后让模板在您选择的特定表上完成您的工作。
我的结论是:T4 很有希望,但“尚未实现”。 它可能适用于非常简单的场景,但现在,我认为它远不如 Codesmith 灵活和强大。
对于 .netTiers 这样的场景,我暂时会坚持使用 Codesmith。
马克
I dabbled in T4 for a bit - hey, if it's free and included in VS2008, use it, right?
My basic idea was to create a set of templates to read a database table, and create our own "roll-your-own" ORM classes from it.
I gave up on T4, frustrated and unable to get even the most basic things to work that are a piece of cake in CodeSmith.
Even a simple task such as selecting what server, database, and table to use cannot be done in T4 efficiently from "outside" the template itself. Yes, you can hard-code all these values as string values into a T4 template - but c'mon, that's really not a solution, is it?
CodeSmith has great support for picking server, database, and tables, and you can set those as properties on the template and just pick what you want and let the template do your stuff on that particular table you picked.
My conclusion: T4 is promising, but "not there" just yet. It might work for very simple scenarios, but right now, it's in my opinion nowhere near as flexible and powerful as Codesmith.
For for a scenario such as .netTiers, I'd stick with Codesmith for the time being.
Marc
T4 不是 CodeSmith。 是的,您可以以 C# 或 Visual Basic 代码的形式在 .tt 文件中指定参数,并使用 <#@ include #> 。 指令来引用代码生成逻辑的实际实现。 这并不比使用 CodeSmith 在 XML 文件中指定相同信息更硬编码。
如需类似 NetTiers 的 T4 模板套件,请查看 S#arp 架构:http://code .google.com/p/sharp-architecture/。
T4 is not CodeSmith. Yes, you specify parameters in a .tt file in the form of C# or Visual Basic code and use an <#@ include #> directive to reference the actual implementation of the code generation logic. This is not more hard-coding than specifying the same information in an XML file with CodeSmith.
For a NetTiers-like suite of T4 templates, check out S#arp Architecture: http://code.google.com/p/sharp-architecture/.
如果您正在寻找一个受良好支持的 DAL 的 T4 实现,该 DAL 是开源的,具有 Linq 接口以及自己的 Fluent 接口,将为表、存储过程、视图等创建包装器。那么您需要尝试 SubSonic 3.0。 SubSonic 2.2 具有相同的优点,但减去了 T4 和 Linq 接口,并且处于发布模式。 SubSonic 3.0 处于 Alpha 阶段,但如果您愿意,您可以下载代码或 .dll 以及 T4 模板。
If you are looking for a T4 implementation of a well supported DAL that is Open Source with a Linq interface as well as its own Fluent interface that will create wrappers for Tables, Stored Procs, Views etc. Then you need to try SubSonic 3.0. SubSonic 2.2 has the same goodness minus the T4 and the Linq interface and is in release mode. SubSonic 3.0 is in Alpha but you can download the code or a .dll and the T4 templates if you like.