In Valid Logic

Endlessly expanding technology

Solution to SubSonic + ReSharper woes

After doing some digging, I managed to figure out what turns out to be a pretty good solution to ReSharper not playing well with SubSonic.  Ultimately, the annoyances fall down to ReSharper's intellisense and syntax highlighting not picking up the classes from SubSonic's generated code.  A good way around it is to actually have code get generated, and luckily, it can be done in a way that is pretty easy to setup, manage, and doesn't take away from the nice features of SubSonic.

The answer is the SubSonic Custom Tool.  Visual Studio allows you to specify a "custom tool" that is used on a file within one of your projects.  The SubSonic Custom Tool is just that.  What it does is on command, it generates the necessary classes based on the SubSonic configuration and your database.

Its installation isn't necessarily the best, since it just tells you to run this "install.bat" (I don't consider that a very good installer), but it doesn't do a whole lot to where it is dangerous or hard to undo if you wanted to.  If you are running Vista, probably need to run it from a command prompt that is in administrator mode.

So anyway, what do you do?

  1. Rename you web.config with your SubSonic settings to subsonic.config (easy enough).
  2. In the Solution Explorer, go to your *.abp file, go to its properties, and change the "Custom Tool" field to "SubSonicCustomTool".
  3. You are done.  This is just a filler.

The Custom Tool generates a code-behind file for your abp file and you are set (may need to set its Build Action to compile... had to do that one time when trying it out in different projects).  Now, has your database changed, so you need to update the code-behind again?  Simply right click on your .abp file and select "Run Custom Tool" and the code will be updated.

A few things to keep in mind:

  • When using plain "website projects" in Visual Studio, you can't specify the build action or custom tool fields on any files.  Those options aren't exposed.  You would have to create a separate class assembly project, move the subsonic.config and abp file there, and then reference it on your website.
  • The custom tool procedure does work on Web Application Projects.  You can have the abp file in the Web Application Project, right alongside your pages and code, since you can specify the build action and custom tool.
  • With this, you can even use SubSonic in WinForms and other EXE-compiled executables in .NET.

Update: In case it wasn't clear, it needs to be a simple web project + a DLL or a web application.  It doesn't need to be a web application and a DLL.  The extra DLL is only needed to make it work with the simple web projects.

Tuesday, March 13, 2007

 
blog comments powered by Disqus