Build and Integration (RSS)

NANT skipping projects on build

If, like me you use Nant to build many projects in one go, then after some time, the list of projects that need to be built can get quite large. All of the build scripts I run tend to build in release mode, though we build locally in debug mode.

I suggest looking through the build logs after adding a new project to make sure that it is actually being built. The other day, I added a new solution to the build and after looking in the logs found that most of the projects were being skipped. The solution was simple. Use the configuration section in the solution properties of Visual Studio to make sure that the mode that you are building in has the projects set to actually build the project. It sounds simple, but it could keep one guessing for a long time after a long week on a Friday afternoon!

Cheers

Rich
with 0 Comments

Nant's strange behaviour : Couldn't find assembly reference

More strange behaviour from NANT today. A new project was started so I made the build script for the new projects that were to be included in the build. When trying to build, it would keep failing, telling me that it couldn't find a few of the references.

The really strange thing was, was that the references were in the correct place on the build server and were obviously there. (I found myself actually talking to the build server at one point, shouting "Can't you see that they are there!"

With verbose on, I could see that the build server was getting itself into a bit of a pickle and that it was looking for the missing assembly references in the administrator's Documents & Settings\Local etc... This was very odd, as other projects that were using the same assmblies and configured the same way were building fine.

The solution
In the end, the way to fix this was just as odd. I had to copy the so-called missing assemblies into the place that the build server thought they were. Once this was done, it would of course build ok. The really curious thing is that after it had built once correctly on the build server, I deleted the files (leaving the real ones stil in place) and all worked fine on concecutive builds.

Cheers

Rich
with 1 Comments

A custom Nant task for deployment

Finally.I got round to automatically deploying our web projects to our development server today in our build script. I thought that it was all going to be very easy. After all, Nant has lots of tasks, ready made to choose from.

When I came o have a look at it, I found that the standard copy task would probably not be suitable. After all, I don't want every file moving over to the dev server from the build server. So the next thing was to look into writing a custom Nant task.

Can I copy project?
First, I thought that I would try and use the EnvDte and VSLangProj references to build a programmatic CopyProject feature, like the one that is built into Visual Studio. This turned out to be pretty easy to code as I have done this before but the problem was that didn't have a version of VS.NET on the build server, just the SDK, and the CopyProject feature needs to create an instance of Visual Studio from its progId. Goodbye to that idea.

Bespoke Copy
In the end, I threw together a class, based on the Nant.Core tasks that would simply copy all files and folders recursively from the source to the target. I am also able to supply a list of files that I don't want to carry over. Something like this:

< copyproject source="C:\Inetpub\wwwroot\MyWebFolder" target="\\MyDevServer\share$\website\MyWebFolder" >
< excludefiles >
< fileextension name="VS Project Files" value=".csproj" />
< fileextension name="VSS Files" value=".vss" />
< excludefiles />
< copyproject />


This is great, but I'll be looking for a way to improve this. I had a bit of a look over the other Nant contrib tasks but couldn't immediately see anything that would be of use. Still, this only took a couple of hours to do and it all works pretty well. Build time is still small for a solution containing 22 projects with a complete deployment of 6 web projects to 2 web servers.

Cheers

R
with 7 Comments

Configure your site to drop anywhere

I've often found that when I build a web app, I need a standard way of recalling certain pages/controls by the full URL.

I also don't want my pages littered with mappath statements. I need to be able to account for what happens when I drop my web application onto another server that has, for example, SSL certificates installed, or perhaps we need to put the application in a directory off the main site.

Well, I think that this way of acheiving this seems to be easy to configure and provides a standard means for any .NET site. Here's what I do...

A small web.config entry

Simply add the following line to the web.config file. This is the only thing that you may ever need to change when you place your site in a different server/folder.

A small method

Add this simple method to a class in your project

public string ProjectUrl()
{
string httpType = "http://";
string baseUrl = HttpContext.Current.Request.Url.Authority;
string projectFolder = ConfigurationSettings.AppSettings["projectfolder"];
if (HttpContext.Current.Request.IsSecureConnection)
{
httpType = "https://";
}
return httpType + baseUrl + projectFolder;
}

Using it

This can be used in all sorts of places. References in user controls, the global.asax for exmaple. If your web directory changes (when publishing from dev - production server for exmaple), just change the web.config entry. Https is already taken care of. Of couse, when you call the method you can just apend whatever page, image, etc.. that you would like on the end.

Cheers R
with 1 Comments

The need for a better build script

My build script is just too verbose. In fact, I am generally too verbose but that's another story. The other day I came to add a new project to my Nant build script and I realised what I had been putting off. My build script just isn't that great. Hey, I'm not saying it's awful but it could do with some tidying up.

When I put together our continuous integration server I was like a kid with a new toy, but quickly found how few examples there are of how to correctly write a really good build script and even more importantly, how long it seems to take to get a good one going.

Currently, my build script for my current project performs the following tasks, all quite simple:

  • Runs all unit tests -that depends on
  • Build each project - that depends on
  • Get latest version from scource safe - that depends on
  • Clean and make directories

The solution isn't huge, about 17 projects at the moment, but there are no settable properties in the build script and I need to change it if I want to build in release mode. It all works pretty well on a daily basis and each developer uses CCTRAY so everyone can see who breaks the build, and when (ok, it was my fault last time), BUT, it could be a lot better. I'd like to hear from people on experiences with Nant and Cruise Control.NET. It would be great to get some definative "this is the way to structure a build script" examples.

the next step will be to add more tasks to the build so it will automatically deploy to a staging server when each build passes.

Cheers

R

with 2 Comments