Anyone have experience calling Rake from MSBuild for code gen and other benefits? How did it go? What are your thoughts / recommendations?

耗尽温柔 提交于 2019-12-04 10:11:17

We did it with Nant/ruby+ERB - it generates a tone of CRUD in our DAL and data entry form input for our web app. for us it works really well, but there was a good amount of setup time in the beginning that made my boss/customer nervous becuase they figured we should be showing more production than prototype.

Also be sure what the generation is doing - there are differences between generate & modify and generate + integrate. generate & modify is more like using a wizard and is one off. when you generate + integrate you need to understand where/how you will exploit the generated code either through inheritance or through library calls from hand written code into the generated code.

Ruby/erb is not fast executing. A method to determine when you do/dont have to generate are helpful becuase compile cycles start to become long and unproductive. We also found it helpful to always build a small test case to generate even a single set of artifacts before integrating it into the work flow - you have a test of the product and it doesnt slow down anyone while you work on the cg element(s).

I would read Jack Herringtons Code Generation in Action as its geared toward Ruby. Its got me into CG.

I would also rea Kathleen Dollards Code Generation in Microsoft .NET. It built for using XSLT but the principles are the same for developing the metdadata, transformation and integration stages. Her articles are also helpful that you find in magazines and around the web.

I use rake to generate configuration files that are templated using ERB. The thing to do is edit your project file to insert a BeforeBuild Target that calls rake, similar to:

<Target Name="BeforeBuild">
     <Exec Command="rake name_of_my_template_processing_task" />
</Target>

See msbuild exec task docs and a blog post on pre-build events. You need in the Command attribute to:

  • supply the path to rake if it's not in the path environment variable already
  • set the working directory attribute if you need it to run from a particular directory
  • supply a -r argument and the path to the rakefile if you're not executing rake from the directory your project is in.

I wanted to just throw this out there (though I doubt it will be an answer to the question, it should be go information), but there are a couple of good CodeGen tools that have some pretty strong Visual Studio integration that can do much of what you want. Obviously you are looking for a Ruby tool, but for those out there who are not comfortable with Ruby, consider some of the other tools:

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