I have a customer coming out tomorrow for a week long gig and as I was preparing for tomorrow's session I needed to set up new project. Starting up a new project and getting all the pieces into place for a Web application involves a fair amount of setup for me usually as I typically startup with a number of standard features plugged into the application, such configuration manager, error handling, logging, email administration (for admin emails) and a handful of other operations. There's also business objects classes and support hookup, a few generic helper pages like the generic MessageDisplay page, an error and log viewer, application status viewer and page for taking an app offline. In addition there are themes and related master page theme setup to handle some of the stock layout. IOW, there are a lot of little details that need to get taken care of to get it all hooked up right. When it's all said and done manually it can easily take an hour to set up a new project from scratch with everything ready. While that sounds like a lot of setup this also provides a ton of canned functionality so once setup there's a big payoff for having all this infrastucture in place.
It's not too often that I create a new production project, so this isn't a big deal even if it does take an hour, but I realized once again today that there's really an easier way using Visual Studio template export. In fact, as it turns out it was actually quicker to export a template from a recent WAP project I've been working on (my WebLog) and just exporting it as a template. What's cool about the template process is that it's a great way to basically take a snapshot of an existing project and turn it into a template. It's very easy to do just off the Visual Studio File menu and I was happily surprised to see that Export Template worked without a hitch with a Web Application Project.
Project Template as a quick Project Copy
So what I did is took my existing WebLog project exported it to a temporary template, then actually created a new project from the template.The new project creates with all the files and settings of the WebLog project. In addition to copying the files the template also fixes up the namespace to match the name of the project. This seems a new feature compared to stock Web project exports where I had to manually embed the project name template expression by hand into each source file - the WAP export (or maybe the class export in general) seems to do a search and replace on the namespace reference which makes templates even easier to create.
In this copy project I now spent about 10 minutes ripping out all the files that are not needed, but leaving in all the infrastructure support files. Things like global.asax with the hookups for error handling and logging, the message display page, the various administration pages that show application status the request and error logs etc. I then cleaned up some of the commonly used files in the application like a App class (which I use as static container which I use for application wide constant and static references for things like my configuration object), and the configuration object.
Some time ago I decided on a common naming scheme for some of these classes that end up in each application, so the the global App object is always App, the application level Configuration class is always ApplicationConfiguration, the Application level cookie manager is always ApplicationCookie, ApplicationUtilities holds all app specific utility routines which in turn uses common ApplicationConfiguration settings for various tasks like custom logging, sending email etc. The common naming makes it easy to use these classes that often depend on each other (especially the configuration class which is always App.Configuration for example).
Now it might seem like all this stuff could go into seperate class libraries to be reused but as it turns out these classes are all very application and Web app specific - they'll end up with a bunch of additional functionality as the app gets going and in many cases functionality gets changed and properties often removed as needed. But the base implementation that's in the template simply provides the most common settings.
Anyway, what's nice about the template is that it was able to quickly make a copy of the project and let me create a new project from the template that I could then modify. Total time so far about 20 minutes.
I now have a project that's truly generic and I make sure I can get that project to compile. Once it does I can create another new template which is what eventually want to end up with - a completely generic project that runs and compiles out of the box.
This is a great way to wrap up functionality.
Using the Template - a little work required with assemblies
Once I have the template now I can create a new starter project and the only thing that I have to do in the new project is add references to my support assemblies or support assembly projects (I tend to work with all of my framework projects open in each application) so I end up having to add 4 projects to my template generated project. I exported a Web Application Project project here and the ZIP file doesn't include the BIN directory or any of Web project's application folders like say images (if you have it). If you need to get these files you need to manually add anything you want copied into the project as content items.
So due to the way references are managed - via the project's relative path links - if you create a new project and the relative path is different it's likely your related assemblies won't be found.
Not a big deal, but something to be aware of.
The Export Template mechanism is a great feature and I often kick myself after having done some repetitive task and not having used this mechanism. You can also export individual items like classes, pages etc. and this can also be a great timesaver. If you haven't taken a look at this feature be sure to try it out - I'm sure you can find some useful ways to take advantage of this functionality!
Other Posts you might also like