Head.SmackOnTable();

Contains Nuts.

Archive for the ‘nant’ tag

Deployment process on CycleMania

without comments

As I have mentioned earlier, I am using a NAnt script to do the building for CycleMania, as I believe that its more geared towards what I need it to do than TeamCity. While TeamCity is a great product in itself, I believe that it either cannot do, or doesn’t make clear, how to copy over files from the build directory into another directory (this being the wwwroot of the website).

The reason why I dont want to point the wwwroot at the subversion root, is for security (.svn folders are browsable by default, and not parsed by asp.net), and because of the way that TeamCity works – when it attempts to do an update, it isnt clear on how to get it to revert all changes made (i.e. to the database), and the database file will be locked, with no way of making it available on the fly.

So, in jumps in NAnt. I know, I could use MSBuild Scripts, or powershell scripting, but I have been using NAnt for some time, and I know it rather well, and its free and runs on machines fairly easily.

A run down of the CycleMania NAnt Script

To start off with, we build the solution file. There is no point doing anything at all if the solution does not compile, so we run the following, After setting a few variables:


<echo message="Building Target"/>
<exec program="${MSBuild.Path}"  basedir="${BaseDir}"  verbose="true" >
<arg value="${SolutionPath}"  />
</exec>

For most of the tasks here, I have verbose set to true, because I want as much information as possible in the log file to see if everything worked, and if it didn’t, why not.

After this, it calls deploy, which has a dependency on clean which does the following:

<target name="clean">
 <exec program="${AppCmdPath}"  verbose="true">
 <arg value="STOP apppool  &quot;${ApplicationPool.Name}&quot;" />
 </exec>
 <delete verbose="true">
 <fileset  basedir="${DestinationDirectory}">
 <include name="*.*"  />
 <include name="**/*.*" />
 </fileset>
 </delete>

<exec program="${AppCmdPath}" verbose="true">
 <arg  value="START apppool &quot;%{ApplicationPool.Name}&quot;" />
 </exec>
</target>

The reason why we insist on shutting down and starting the application pool back up is because of MSSQL and IIS and their relationship. For some reason, if you simply recycle the application pool, it dosent stop the database that is bound to it (a user instance), so you cannot simply update the file in the App_Data folder, as I found out the hard way, which eventually led me down this path. It seems that if you want to be able to properly delete everything, you can kill the app pool, and it will unlock all the files. Because we are ussing IIS 7.5 on this box, we have to ues appcmd (google for it!), which is alot better than using iisreset, especially since I have other sites running on the box ;)

One thing I have considered doing, but dont really have time for, is maybe copying over an app_offline file, so that if someone does hit the site while its being wiped, they can see a friendly error page as opposed to an empty directory listing, or something worse than that, but at the moment, that is low priority for me.

And now, deploy gets called:

<target name="deploy" depends="clean">
 <copy  todir="${DestinationDirectory}" verbose="true">
 <fileset  basedir="%{BaseDir}\Cyclemania.Web">
 <include name="*.*"  />
 <include name="**/*.*" />
 <exclude name="*.cs" />
 <exclude name="*.resx" />
 <exclude name="*.csproj" />
 <exclude  name="*.projdata" />
 <exclude name="*.sln" />
 <exclude name="*.csproj.user" />
 <exclude name="*.suo" />
 <exclude name="*.scc" />
 <exclude name="*.load" />
 <exclude  name="*.vssscc" />
 <exclude name="*.vspscc" />
 <exclude name="obj\**" />
 </fileset>
 </copy>
</target>

Notice, it will only copy files that are not on the exclude list – 99.9% those files arnt needed on a live system, but you can tweak it as required. Im looking to keep the wwwroot of the application as clean as possible, and I dont see much need to copy those files over.

And there you have it! With this script (and the bits that I have missed out), you should have a fully functioning build script that will automatically build it for you, wipe the target directory, and copy over the new files. And yes, it works.

Written by Monty

January 2nd, 2010 at 9:34 pm

Posted in .NET, CycleMania

Tagged with , ,

MS Build – “Microsoft.WebApplication.targets” was not found.

with one comment

This is a stupid error, an oversight by Microsoft. As far as I can tell, you can ONLY install the Web Application pack for vs2005 if you have VS installed – you cant install it on a build server, which is nice and “fun”.

A solution is to just create the directory structure it asks for -

C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications\

And copy over the files from your own copy. I don’t know why Microsoft did it this way, but its criminally retarded.

Edit – You can now download the file from here.

Written by Monty

July 22nd, 2008 at 10:13 am

Posted in .NET

Tagged with , , , , ,