Visual Studio T4 与 CodeSmith
过去 2 年我一直在使用 CodeSmith,并且喜欢它为我所做的一切。不过,我也了解 Visual Studio 中内置的 T4,它也可以做一些非常酷的事情。根据与朋友的对话,VS2010 中的 T4 T4 会更好。
所以问题是:我是否继续乘坐 CodeSmith 巴士,或者是时候开始将我的所有模板转换为 T4 了?
更新 也许我问问题的方式不太清楚。显然,在新模板正常工作之前,我不会删除我的 cs 模板并停止使用它们。然而,此时此刻还值得付出努力吗?目前 T4 是否比 CodeSmith 具有更全面的优势?是否有一些功能或功能集,通过为 T4 编写模板,我会看到效率提高 100 倍?
I've been using CodeSmith for the past 2 years and love what it does for me. However, I also know about T4 which is built in to Visual Studio and can do some pretty cool stuff too. Based on conversations with friends T4 in VS2010 T4 is going to be even better.
So the question is: do I keep riding the CodeSmith bus or is it time to start converting all of my templates to T4?
Update
Perhaps I wasnt clear in the way I asked the question. Obviously I'm not going to delete my cs templates and stop using them until I have the new templates working. However, is it even worth the effort at this point? Does T4 at this point offer a compleling advantage over CodeSmith? Is there some feature or set of features that by writing my templates for T4 instead I'll see a 100X improvement in my effeciency?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 T4 感到非常兴奋和兴奋,并尝试将我所有的 CodeSmith 东西转换为 T4 - 结果发现 T4 有很多问题/缺乏。
查看 Kathleen Dollard 的 < a href="http://msmvps.com/blogs/kathleen/archive/2009/03/17/what-s-wrong-with-t4.aspx" rel="noreferrer">T4 有什么问题博客文章 - 她几乎是 .NET 上的代码生成女王,她总结得很好 - 我完全 100% 同意她的问题。
总而言之,经过大量的尝试和尝试,我基本上放弃了 T4 - 它还没有准备好迎接黄金时段,至少对于我正在使用的模板类型来说还没有做好(主要是检查数据库表以提取值,例如作为自制 ORM 的基础,或者从数据库中提取常量和配置设置等)
并且通过在 VS2010 中使用 T4 进行实验,我不确定其中有多少已得到修复,真的......不是看起来很多。还有一些其他有趣的概念(预处理模板,据说< a href="http://blogs.appventure.com/Kathleen/2009/10/22/T4TemplatesNativelySupportParameters.aspx" rel="noreferrer">支持参数等),但大多数基本缺陷仍然看起来徘徊......
所以现在:不要抛弃 CodeSmith!也许 VS2016 中的 T4 也会同样强大......但在那之前......
资源:
I was very thrilled and excited about T4 and tried to convert all my CodeSmith stuff to T4 - only to learn there's quite a few things that are wrong with / lacking from T4.
Check out Kathleen Dollard's What Wrong with T4 blog post - she's pretty much the Queen of Code Generation on .NET, and she sums it up very nicely - I totally agree 100% with her issues.
All in all, after a lot of playing around and trying, I have largely given up on T4 - it's just not yet ready for prime-time, at least not for the type of templates I was working with (mostly inspecting database tables to extract values, e.g. as foundation of a homemade ORM, or to extract constants and configuration settings etc. from the database)
And from experimeting with T4 in VS2010, I'm not sure how much of this has been fixed, really.... not a lot, it seems. There are a few other interesting concept (preprocessed templates, supposedly support for parameters etc.) but most of the basic flaws still seem to linger.....
So for now: don't throw out CodeSmith just yet!! Maybe T4 in VS2016 will be just as powerful.... but until then.....
Resources: