Skip to the content Back to Top

Update: the title of this post is probably misleading as it's not all the steps for using SubSonic. There's plenty of material out there already on that (for i.e. how to set your build provider for Web Site Projects, how to set your config files for class libraries or Web Application Projects, how to set up your database, etc.) - the best place to start looking for that info is This post refers to how to get using the subsonic.exe from within Visual Studio to regenerate your code on demand.

I've been using SubSonic for one of my latest projects and I really like what I've seen thus far. I'll save a further review for a possible other post, but since I've just repaved my machine and I'm setting everything back up again, I had forgotten how to configure the Visual Studio IDE to easily regenerate code using SubSonic (with a Web Application Project or Class Library - not the auto build provider).

Rob Conery has a good Webcast on how to do it all (if you haven't viewed it yet, head over now and do so), but it's a little tedious to work your way through the whole Webcast in order to pick out tool setup instructions. Therefore, I figured I'd jot down how to set up SubSonic DAL generation scripts for easy generation of code in Web Application Projects or Class Libraries. In other words, instead of having to open a command prompt all the time and specify what you want generated and where etc., just create some toolbar items and/or macros to do it for you on demand right in the Visual Studio IDE.


Reference External Tool

  • Tools -> External Tools -> Add
  • Settings for new External Tool:
    • Title: SubSonic DAL
    • Command (to your local sonic.exe location): C:\Program Files\SubSonic\SubSonic 2.0.3\SubCommander\sonic.exe
    • Arguments (means execute the generate command to, in my case, a generated directory in my class library - in other words, where my web.config/app.config file is with all SubSonic config options set): generate /out Generated
    • Initial Directory: $(ProjectDir)
    • Use Ouput window: checked
    • Prompt for arguments: checked (optional)




Create SubSonic toolbar with SubSonic DAL button (optional)

  • Right-click anywhere on blank menu bar and select "Customize"
  • Click "New" for new toolbar and save as "SubSonic":

  • Switch to Commands tab and then select category "Tools"
  • Select External Command n where n is the position of your newly referenced SubSonic DAL tool in the Tools menu:

    In the screen shot above, it's External Command 6. On a new machine with nothing else on it, the number will be External Command 2 as there's only one other tool before it in the menu (Dotfuscator Community Edition).
  • Drag and drop External Command n to the floating SubSonic menu you had just created:

  • When you now press close on the Customize dialogue, your SubSonic menu should now reflect your tool name. In this case that would be "SubSonic DAL."
  • Drag your floating toolbar to wherever you want it on your menu bar. Now, to generate code you can click on it from the Tools dropdown menu, or directly on your menu bar. Of course, you could just go further and create a macro.
  • Note: make sure you're actually in your SubSonic project where your app.config is located when you execute the command - nothing bad will happen if you don''s just that nothing good (code generation) will happen either.



Create another external tool that runs the SubSonic DB versioning command (scripts schema and data for your database!)

  • Do exactly as above for the SubSonic DAL tool, but instead put in the command "version /out \DB"


Let Us Help You!

We're Librarians - We Love to Help People