how to modify SubSonic 2.1 code generation

强颜欢笑 提交于 2019-12-08 00:55:22

问题


I would like to add basic logging and make some other minor changes to the classes generated by SubSonic 2.1 (I'm not using SubSonic 3.0 t4 templates).

Is there a way to do this without modifying the SubSonic source code?


回答1:


You have two choices. You can modify the default templates or create your own. I suggest making your own templates which will lives side-by-side with the original and then generate your code via the following instructions.

Note that these steps assume you ran the default SubSonic installation. In other words, Sonic.exe and the default templates can be found under c://program files/. If not, you'll find your SubSonic files/templates in an alternative installation location, of course.

  1. Make a copy of the default templates folder as found in C:\Program Files\SubSonic\SubSonic 2.1 Final\src\SubSonic\CodeGeneration\Templates. I might recommend naming the copied folder "TemplatesWithLogging.”
  2. Open the aspx files in Visual Studio and modify to your heart’s content. For example, I wanted an alternate C# class template so I modified CS_ClassTemplate.aspx. If you want to merely alter the default templates, you can but I suggest making a backup first.
  3. I am going to assume you are already familiar with code generation with SubSonic. I personally like to setup a Visual Studio External Tool to allow for quick, pre-configured regeneration. Otherwise, the following can be ported over to the command line. Here’s the External Tool setup instructions:

    • Tools > External Tools > Add Title: TemplatesWithLogging

    • SubSonic Classes Command: C:\Program Files\SubSonic\SubSonic 2.1 Final\SubCommander\sonic.exe Arguments: generate /out Generated /namespace NAMESPACE /server SERVER/db DATABASE where NAMESPACE, SERVER and DATABASE are replaced accordingly.

    • Initial Directory: $(ProjectDir)

    • Check “Use Output window” and “Prompt for arguments.”

    • Select Apply or OK

4.Select the project which will contain the “Generated” folder and auto-generated files. Select Tool > TemplatesWithLogging.

You can find more here.




回答2:


Yes you can modify the templates that version 2 uses, they're just aspx files. The templates are stored in src\SubSonic\CodeGeneration\Templates under your installation directory.

This blog post goes into more detail:

http://johnnycoder.com/blog/2008/06/09/custom-templates-with-subsonic/



来源:https://stackoverflow.com/questions/1217845/how-to-modify-subsonic-2-1-code-generation

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