Head.SmackOnTable();

Contains Nuts.

Creating a CI server using CC.Net Part 1

without comments

For the CycleMania project, I previously used TeamCity, but I think it is more geared towards building static projects and running tests rather than deployment, so this time around im going to be using CruiseControl.NET

Note – I am doing this and writing this at the same time :)

To get started, you need to install the following:

  • Subversion for windows, command line, from Collab.NET
  • NAnt, I have version 0.85 installed, and put the path into the PATH environment variable, I am NOT using 0.86beta1 because of this error:
NAnt 0.86 (Build 0.86.2898.0; beta1; 12/8/2007)
Copyright (C) 2001-2007 Gerry Shaw

http://nant.sourceforge.net

BUILD FAILED

Failed to initialize the 'Microsoft .NET Framework 2.0' (net-2.0) target framework.

 Property evaluation failed.
Expression: ${path::combine(sdkInstallRoot, 'bin')}
 ^^^^^^^^^^^^^^

 Property 'sdkInstallRoot' has not been set.

For more information regarding the cause of the build failure, run the build again in debug mode.

Try 'nant -help' for more information

Even though we do NOT need the .net 2.0 SDK! Very poor show indeed.

  • CruiseControl.Net – you probably want to set the admin password to something else from the config file loctated in the webdashboard directory (inside where you installed cc.net), the file is dashboard.config

Once you have the above monkies installed, you want to do a checkout of the CycleMania source code to a directory, like so:


svn co https://cyclemania.svn.codeplex.com/svn/trunk E:\SVN\CycleMania

Replace the E:\SVN\CycleMania with wherever your subversion repository lives.

For sake of argument, I have my build scripts living in E:\SVN\CycleMania-BuildScript, and the file is called CycleMania.build

Once you have done that, go into the build script, and type in nant, and you should get the following:

E:\SVN\CycleMania-BuildScript>nant -buildfile:CycleMania.build
NAnt 0.85 (Build 0.85.2478.0; release; 10/14/2006)
Copyright (C) 2001-2006 Gerry Shaw

http://nant.sourceforge.net

Buildfile: file:///E:/SVN/CycleMania-BuildScript/CycleMania.build
Target framework: Microsoft .NET Framework 2.0
Target(s) specified: build

build:

 [echo] Building Target
 [exec] Starting 'c:\Windows\Microsoft.NET\Framework64\v4.0.30128\MSBuild.exe ( E:\SVN\CycleMania\CycleMania.sln)' in 'E:\SVN\CycleMania-BuildScript'
 [exec] Microsoft (R) Build Engine Version 4.0.30128.1
 [exec] [Microsoft .NET Framework, Version 4.0.30128.1]
 [exec] Copyright (C) Microsoft Corporation 2007. All rights reserved.
 [exec] Build started 2/23/2010 3:47:11 PM.
 [exec] Project "E:\SVN\CycleMania\CycleMania.sln" on node 1 (default targets).
 [exec] ValidateSolutionConfiguration:
 [exec]   Building solution configuration "Debug|Mixed Platforms".
 [exec] Project "E:\SVN\CycleMania\CycleMania.sln" (1) is building "E:\SVN\CycleMania\Cyclemania.Web\Cyclemania.Web.csproj" (2) on node 1 (default targets).

 [exec] E:\SVN\CycleMania\Cyclemania.Web\Cyclemania.Web.csproj(649,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualS
tudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exi
sts on disk.
 [exec] Done Building Project "E:\SVN\CycleMania\Cyclemania.Web\Cyclemania.Web.csproj" (default targets) -- FAILED.
 [exec] Done Building Project "E:\SVN\CycleMania\CycleMania.sln" (default targets) -- FAILED.
 [exec] Build FAILED.
 [exec] "E:\SVN\CycleMania\CycleMania.sln" (default target) (1) ->
 [exec] "E:\SVN\CycleMania\Cyclemania.Web\Cyclemania.Web.csproj" (default target) (2) ->
 [exec]   E:\SVN\CycleMania\Cyclemania.Web\Cyclemania.Web.csproj(649,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Visua
lStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
 [exec]     0 Warning(s)
 [exec]     1 Error(s)
 [exec] Time Elapsed 00:00:05.22

BUILD FAILED

E:\SVN\CycleMania-BuildScript\CycleMania.build(7,4):
External Program Failed: c:\Windows\Microsoft.NET\Framework64\v4.0.30128\MSBuild.exe (return code was 1)

Total time: 12.9 seconds.

HUH?!? What the hell happened there? Well in the infinate wisdom of Microsoft (which I have blogged about before), they did not decide to include the Microsoft.WebApplications.targets file anywhere to be found on the hdd, and you have to dig it out from the vs.net install, or you can find it from this handly link! Unzip this into your Program Files or Program Files (x86) if you are fancy and have a 64bit proc.

Once you have unzipped that lovely glorious file, and run the NAnt script again, you should see a better output, with LOADS of stuff hapenning, and hopefully at the end, these GLORIOUS WORDS:


BUILD SUCCEEDED

Total Time: 11.6 seconds

Note: Your time may vary.

In Part 2, I will describe how to set up your SQL 2008 instance up, user accounts (NOTE, I would do this properly as opposed to the hacky “lets get the site to work” way), and IIS…

Written by Monty

February 24th, 2010 at 1:05 am

Posted in .NET, CycleMania

Tagged with , ,

Slowness with Windows 7

without comments

Well, recently I have been having trouble with my Win7 installation. I was getting very frequent slowdowns (every 2-3 seconds), but only if I used the hdd, if I was playing around with something in memory, then it was perfectly fine. Playing games could get rather frustrating because of the slowdowns, but once everything was loaded into memory, it was ok

After some research, and getting incredibly pissed off with my machine, to the point where I was convinced it was a hardware fault after disabling a bunch of services, updating all the drivers, antivirus, all the extra faff in windows, in one of my moments of desperation before I waved bye bye to my machine, I had a look in Resource Monitor, you know the little button located in the Task Manager’s Performance tab?

Well under there, I noticed that a certain process was hammering the hard disk, wmpnetwk, and whenever it seemed to hit the hard disk, I would get a slow down. After some research on the all mighty tinterweb, its the Windows Media Player Network Sharing Service, basically for streaming your stuff to other pc’s and/or Xbox etc, and from what I read online, that if it comes across a corrupted (or half downloaded .avi’s which I have loads of, after trying to convert a few vid’s for my friends), it tends to hammer the hard drive. Once I disabled this service, my PC was lightning fast!

Written by Monty

February 16th, 2010 at 7:41 pm

Posted in Misc

Resharper and its “Convert to LINQ expression”

without comments

I guess im a bit old fashioned, but I like to write code like:

public static List<string> CovertLongListToString(IEnumerable<long> param)
 {
 List<String> returnList = new List<string>();

 foreach (long l in param)
 {
 returnList.Add(l.ToString());
 }

 return returnList;
 }

But then resharper 5.0 gives me this lovely option of “Convert to LINQ Expression”, and it turns into:


public static List<string> CovertLongListToString(IEnumerable<long> param)
 {
 return param.Select(l => l.ToString()).ToList();
 }

Thats just brilliant! I LOVE YOU RESHARPER!

Written by Monty

January 23rd, 2010 at 2:50 pm

Posted in .NET

Tagged with ,

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 , ,

Deleting all data from a Database

without comments


SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']'
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id
UNION ALL
SELECT 'TRUNCATE TABLE ' + name FROM dbo.sysobjects WHERE (type = 'u') and name != 'sysdiagrams'
UNION ALL
SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' ADD CONSTRAINT '  + f.name + ' FOREIGN KEY (' + COL_NAME(fc.parent_object_id, fc.parent_column_id) + ') REFERENCES ' + OBJECT_NAME (f.referenced_object_id) + '(' + COL_NAME(fc.referenced_object_id, fc.referenced_column_id) + ')' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id

Written by Monty

December 25th, 2009 at 6:09 pm

Posted in Code Snippet

Tagged with

Deeploading with NetTiers

without comments

Once you get your head around the DeepLoading and Inclusive/Exclusive Lists in NetTiers, its not too hard, but it isnt straightforward to start off with. Take this VERY simplified class, as an example:


class Product
{
public TList<Product> ChildrenProducts {get;set;}
public Product ParentProduct {get;set;}
}

If you want to deepload the ChildrenProducts collection, you think youd run the following:


DataRepository.ProductProvider.DeepLoad(product,true,DeepLoadType.IncludeChildren, new []{typeof(Product)});

But that will load the ParentProduct product, and not your ChildrenProducts collection, even though its just a list of Product.

What you want to do is:


DataRepository.ProductProvider.DeepLoad(product,true,DeepLoadType.IncludeChildren, new []{typeof(TList<Product>)});

Written by Monty

December 22nd, 2009 at 4:40 pm

Posted in .NET, NetTiers

Tagged with ,

Using NAnt 0.85 with .net 4.0

without comments

Im guessing because the .net 4.0 framework is still in the beta stages, that’s why NAnt (and TeamCity) arnt supporting it, but from what I can tell, mstcthe method to build it hasnt changed since .net 2.0’s msbuild way of compiling a solution.  Basically, all you need to do is call msbuild from the command line, give it the path of the solution, and off it goes to build it. You can specify additional information such as the build target etc, but its not essential.

Whereas normally, within NAnt, you would run the following:


<solution configuration="release" solutionfile="test.sln" />

This aparently dosent work with the .net 4.0 framework, it seems to not detect it. From what I can tell, the quickest way around this is to do the following:


<exec program="c:\Windows\Microsoft.NET\Framework64\v4.0.21006\MSBuild.exe" basedir="C:\SVN\CycleMania\"  verbose="true" >
 <arg value="C:\SVN\CycleMania\CycleMania.sln" />
 </exec>

Obviously, change the path in the program attribute to suit where Windows is located, and change the Framework64 to simply Framework if you are not running on a 64bit platform. One quirk that I fonud is that you have to have the BaseDir as where the solution is based, otherwise it throws errors about it cannot build properly.

And that should be it! If you are still struggling to compile on the .net 4.0 framework from within Nant, give me a shout.

Written by Monty

December 19th, 2009 at 12:02 pm

Posted in .NET, CycleMania

Tagged with , ,

CycleMania’s Continuous Integration

without comments

Its now public knowledge that I have been working on getting a decent CI integration for the CycleMania project working on a publicly accessable server.

For the record, we are using the following tech for the CI integration. Yes, I WILL write a very detailed how-to on how I set things up, but as I am on my lunchbreak here at work, heres a very quick overview of what we are using:

  • TeamCity 5.0 Professional, a free download from JetBrains (Limit of 20 Projects and 20 Users)
  • .Net framework 4.0 Beta 2 (obviously)
  • Nant 0.85, not as a proper build script, but purely as a glorified as a batch script
  • APPCMD command to control IIS7’s App recycling (From inside Nant)
  • .Net 4.0’s MSBuild

All this running ontop of Windows 2008 R2 Web Edition, and SQL Server 2008 Express.

Things I have learned is:

  • TeamCity 5.0 isnt geared up for .net 4.0 YET, which is fair enough, they said support will be included in 5.1
  • TeamCity also seems to be simply geared for building projects and running unit tests, less so for copying files over to another directory with specific paths etc.
  • Nant’s contrib project is crap. Fair enough last time it was updated was 3 years ago, but it dosent work.
  • You cannot simply recycle an app pool to kill a user instance of SQL Server 2008, to update the .mdf file.
  • You really shouldnt run a site from the same directory as SVN, if you plan to update it (re above)
  • Nant is all good and well, but also dosent support .net 4.0.

I promise I will expand on most of these points when I have time!

Written by Monty

December 18th, 2009 at 3:37 pm

Javascript – Encoding

without comments

The escape() method does not encode the + character which is interpreted as a space on the server side as well as generated by forms with spaces in their fields. Due to this shortcoming and the fact that this function fails to handle non-ASCII characters correctly, you should avoid use of escape() whenever possible. The best alternative is usually encodeURIComponent().

escape() will not encode: @*/+

Use of the encodeURI() method is a bit more specialized than escape() in that it encodes for URIs [REF] as opposed to the querystring, which is part of a URL. Use this method when you need to encode a string to be used for any resource that uses URIs and needs certain characters to remain un-encoded. Note that this method does not encode the ' character, as it is a valid character within URIs.

encodeURI() will not encode: ~!@#$&*()=:/,;?+'

Lastly, the encodeURIComponent() method should be used in most cases when encoding a single component of a URI. This method will encode certain chars that would normally be recognized as special chars for URIs so that many components may be included. Note that this method does not encode the ' character, as it is a valid character within URIs.

encodeURIComponent() will not encode: ~!*()'

Shamelessly stolen from xkr.us – This can very well bite you on the ass.

Written by Monty

December 15th, 2009 at 11:31 am

Posted in Misc

Disable Warning As Error on WEBSITE project

without comments

Well after spending half an hour looking on the net on how to disable WarningAsError on a WEBSITE project, everyone kept saying the same thing – edit the project settings – WELL A WEBSITE PROJECT DOSENT HAVE PROJECT SETTINGS!

Anyway, here is the solution, you need to edit your web.config :

<system.codedom>
 <compilers>
 <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="3" compilerOptions="/d:DEBUG;TRACE">
 </compiler>
 </compilers>
</system.codedom>

Should turn into the following:

<system.codedom>
 <compilers>
 <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="3" compilerOptions="/d:DEBUG;TRACE">
 <providerOption name="WarnAsError" value="false"/>
 </compiler>
 </compilers>
</system.codedom>

The line you want in question is:

<providerOption name="WarnAsError" value="false"/>

And this baby will make it work! Enjoy!

Written by Monty

December 8th, 2009 at 5:30 pm

Posted in Misc