Visual Studio T4 与 CodeSmith

发布于 2024-08-27 03:48:40 字数 338 浏览 5 评论 0原文

过去 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鱼窥荷 2024-09-03 03:48:40

我对 T4 感到非常兴奋和兴奋,并尝试将我所有的 CodeSmith 东西转换为 T4 - 结果发现 T4 有很多问题/缺乏。

  • 不支持模板参数 - 您需要将所有内容硬编码到模板中...
  • T4 的 Visual Studio 主机相当有限
  • ,不支持单个模板的多个输出文件

查看 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.

  • no support for parameter for your template - you need to hard-code everything into your template.....
  • the Visual Studio host for T4 is rather limited
  • no direct and easy support for multiple output files from a single template

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文