Tuesday, June 1, 2010

Running Quartz.Net 1.0.2 on .Net 4.0

NOTE: I'm now blogging at http://jayvilalta.com/blog and not updating this blog anymore. For information on the latest version of Quartz.Net, visit me there.

We recently upgraded one of our application to .Net 4.0. As part of this upgrade, we also upgraded out Quartz.net jobs to run on the 4.0 version of the .Net framework. The process was fairly straightforward, but not without surprises, so I figured I would post it here in case it’s useful. I hope that there will be an official 4.0 release made soon, so I have only included the steps of the process I followed in this post. If there’s enough interest I can upload the updates solution file. If you want to try it out for yourself, I’ve broken the process down into simple steps. Feel free to skip over the steps that are familiar to you.

Step 1 – Downloading the Source Code

First, I downloaded the source code from sourceforge using subversion. The subversion url for the project is: https://quartznet.svn.sourceforge.net/svnroot/quartznet. If you’re using TortoiseSVN, then you just have to right click on the folder you want to download the source to, and then select SVN Checkout. Paste the URL above into the box and select OK. Here’s a screenshot of what I’m talking about:
image

Step 2 – Convert the Solution File

Next locate the main solution file for the maintenance release (this is the branch I used, since it corresponds to the latest released version). The file is called Quartz.2008.sln and is located under branches –> Quartz-1.0-Maintenance. Open this file in VS2010 (right click, select open with… VS2010) and run through the upgrade wizard. Once that’s done, there are some small changes to be made.

Step 3. – Target .Net 4.0

This is the tedious part… you’ll have to right click on each project, select properties and then under the Applications tab, select the new target framework:
image

Step 4 – Fix the Build

If you build the solution now, you’ll get some warnings are errors. You have 2 options:
1. Fix the errors, which are basically documentation errors. You’ll have to look at each of the individual errors to fix them, so I won’t describe the process in detail. Just keep pressing F8 until you’ve fixed them all.
2. Turn off warnings as errors. This is the path of least resistance.
At this point, whether you selected option 1 or 2, you should have a working build. By default, the results of the build are put under the build\2.0 folder:
image

Step 5 – Fix the Version Number and Service Name

Note: this part is optional…
Since I already have a working scheduler and didn’t want to risk screwing it up, I changed the name of the scheduler in the installer file so that I could install it side by side with my existing scheduler to be able to test it. I also changed the version numbers in case for some reason the dlls got mixed up. To change the service name, open Configuration.cs file. It’s under the Quartz.Server.Core project. Change these lines as follows (or use your imagination):
private const string DefaultServiceName = "QuartzServerForNet4";

private const string DefaultServiceDisplayName = "Quartz Server For Net4";

private const string DefaultServiceDescription = "Quartz Job Scheduling Server For Net4";



This will let you install the updated scheduler side by side with the old scheduler.


To update the version number you will have to right click on each project, select properties and then under the application tab, click on the Assembly Information button to update it:


image


Then just, update it to the version number of your preference. Something like this:


image


Step 6 – Final Steps



You should be ready to use Quartz.Net with the 4.0 framework now. If you’re going to install Quartz.net as a service, then take a look at this post. The steps you need to follow will be identical, just remember to use the new files you just built. If you are running Quartz.net embedded in your application, then update your references so they point to the new dlls.