T4 code generation without Visual Studio 2010?

瘦欲@ 提交于 2019-12-04 09:00:58
Michael Maddox

TextTransform.exe will do what you want for simple scenarios:

http://msdn.microsoft.com/en-us/library/bb126245.aspx

Here is how to run a T4 template from your own code for templates created in VS 2010:

http://msdn.microsoft.com/en-us/library/ee844259(VS.100).aspx

And here is how to run a T4 template from your own code for templates created in VS 2008:

http://www.capprime.com/software_development_weblog/PermaLink,guid,104d9faf-5780-42ca-88e5-c04cb88f61b3.aspx

There will be some issues running Subsonic T4 templates outside Visual Studio:

How can I automate the t4 code generation for SubSonic

I would stick to T4 rather than roll your own template engine.

Oleg Sych

T4 is a part of Visual Studio. If your ORM tool can assume that Visual Studio is available, T4 is a good choice. You have an option of redistributing the Visual Studio shell, which also includes T4, with your application. Alternatively, you can use preprocessed templates to compile the templates into executable code generators. In compiled form, these templates don't require Visual Studio, but also cannot be modified.

Oleg

AFAIK T4 templates are invoked from within Visual Studio IDE.

Building an ORM needs more than text templates. I suggest you look into AtomWeaver (at http://www.atomweaver.com) which is a code generator that lets you build models from individual building blocks (called "Atoms"). These Atoms are smart templates that act both as text templates but also as mini-programs, allowing you to do much more that simple string substitution.

You can develop your own "Atoms" that transform a database structure into source code. Then, for each new database, you combine these Atoms to build your schema, and fire up the generator to obtain the source code. Because what you've built was actually a model of your DB, you can later make any changes and regenerate your code.

AtomWeaver implements ABSE, a kind of model-driven software development (has nothing to do with UML or MDA). Learn the mechanics of ABSE at http://www.abse.info

AtomWeaver is presently in public beta. There isn't much documentation at this point, so you may have a hard time getting up to speed with it.

There is a command line utility called TextTransform.exe you can use to generate code for a T4 template. I can't comment on if it is the right tool for building a ORM, but I like it well enough for generating state machines from an XML file.

http://msdn.microsoft.com/en-us/library/bb126245.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!