Posts tagged ‘build’

TeamCity replacing build agent

We have the Professional version of TeamCity at work which allows 3 build agents / machines and 20 users. It’s big enough for our efforts. We just put an old build machine to bed and a new one is coming online. However I could not find how to remove agent from the TeamCity interface. First I uninstalled the agent on the old build machine, but the profile was still on the server. I ended up going into the Oracle TeamCity database and deleting the profile from the AGENTS table. After that I was able to add the new build agent in the TeamCity server console.

Custom Nant Task

When using Nant there is not much you can say is lacking. Sometimes you find yourself wondering why you are cutting and pasting good amount of code between different scripts. There has to be a better way of reusing code and sure enough there is. Just write your own Nant extension and it’s pretty simple, let’s take a look.

First create a class that extends the nant Task then declare the name of the task and setup the properties you want available to the user. Lastly you will have ExecuteTask procedure that will be called by Nant when your Task executes. That’s all the magic !

[TaskName(“setVersionAssembly”)]
    public class CxSetVersionAssembly : NAnt.Core.Task
    {
        [TaskAttribute(“file”, Required = true)]
        [StringValidator(AllowEmpty = false)]
        public string file
        {
            get { return msAssemblyFile; }
            set { msAssemblyFile = value; }
        }

        [TaskAttribute(“buildNumber”, Required = true)]
        [StringValidator(AllowEmpty = false)]
        public string buildNumber
        {
            get { return msBuildNumber; }
            set { msBuildNumber = value; }
        }

        // Executes the nant task
        protected override void ExecuteTask()
        {
            // Don’t catch errors, it will display in the build log if any
            Project.Log(Level.Info, “start setVersionAssembly”);
            ChangeAssemblyVersionNumber(msBuildNumber, msAssemblyFile);
        }
}

When you use it in your Nant script you will have to load your assembly first. Once your assembly has been loaded you can start using your custom Task.

<loadtasks assembly=“bin\debug\DE.Nant.Extensions.dll”/>

    <setVersionAssembly
         file=“${tempFile}”
         buildNumber=“3.333.3.3000”
    />

This is a very brief and simple example, there are bunch of properties and other goodies you can use as you build out your custom Nant Tasks.

The Custom Nant Task I wrote is used to update the version of our .net assemblies during build. Attached is the complete code including Nant script and unittests. Get the code

Ant script, build Apache 2.2 and Mod_ssl

A friend of mine wanted to run the latest Aspache Mod_ssl available as some vulnerable holes have been patched in OpenSsl, but in order to do that you need to build it your self. Can you take a look he said, sure why not, he gave me a couple of links for instructions which is really all you need.

Instructions
Apachelounge
Devside

Source code(s)
OpenSsl
Apache
Zlib

Now I’m expecting my friend will need to do this again with another version in the future. So I figured why don’t we just create Ant script out of it. That way next time around we only need to change a couple of params about the source packages and we are off to the races. One click ant script should do the trick.

There are a couple of things that you have to have installed first on your system before you start. One is perl, I’m using ActivePerl but you should also be able to use other compatible perl packages. Another is awk, you might have to use gawk which you can then rename as awk on you computer before you start. Both of those need to be installed and available in the system path. I also have Vs2005 installed and that’s the one that will be used to do the compile. Also Zdll.lib was extracted from the Zlib binary as I got up against naming conflict on that one, put that one in \lib\zlib

Of course a simple Ant script to compile those would be impossible without the instructions mentioned before. And of course above all the people that put in the work to create the make files etc. Without them I would still be lost !

Here is the Ant script,

<project name=“nativeIndian” default=“ApacheBuild” basedir=“.”>

        <!–
    11/2009 – ORN
    ===
    – Apache –
    http://www.apachelounge.com/viewtopic.php?t=778
    http://www.devside.net/guides/windows/apache
    –
    http://www.openssl.org/source/
    http://httpd.apache.org/download.cgi
    http://www.zlib.net/

    ****
      Note –
      ActivePerl and Awk need to be present and available in the path.
      VS2005 is used to compile.
    ****

    This script will attempt the following
    ==========================================
    * Unzip sources
    * Set sources in place for compile
    * Compile OpenSsl
    * Test OpenSsl
    * Compile Apache
        –>

        <!– set global properties for this build –>
  <property name=“ApacheName” value=“Apache22” />
  <property name=“srcDir” location=“${basedir}/../” />
  <property name=“libDir” location=“${basedir}/../lib/” />
  <property name=“zipLibDir” location=“${basedir}/../lib/zlib/” />
  <!– Source –>
  <property name=“OpenSslTop” value=“openssl-0.9.8l” />
  <property name=“OpenSslSourceGz” location=“${basedir}/../${OpenSslTop}.tar.gz” />
  <property name=“OpenSslSourceTar” location=“${basedir}/../${OpenSslTop}.tar” />
  <property name=“ZlibTop” value=“zlib-1.2.3” />
  <property name=“ZlibSourceGz” location=“${basedir}/../${ZlibTop}.tar.gz” />
  <property name=“ZlibSourceTar” location=“${basedir}/../${ZlibTop}.tar” />
  <property name=“ApacheSourceTop” value=“httpd-2.2.14” />
  <property name=“ApacheSource” location=“${basedir}/../${ApacheSourceTop}-win32-src.zip” />
  <property name=“ApacheBin” value=“Apache_bin.zip” />
  <!– Build dirs–>
  <property name=“buildDir” location=“${basedir}/aphache/” />
  <property name=“buildLibDir” location=“${buildDir}/${ApacheSourceTop}/srclib/” />
  <property name=“buildLibZlibDir” location=“${buildDir}/${ApacheSourceTop}/srclib/zlib/” />
  <property name=“buildLibOpenSslDir” location=“${buildDir}/${ApacheSourceTop}/srclib/OpenSsl/” />

  <!– Hardcoded, VS2005 location –>
  <property name=“VsEnvir” location=“D:\apps\dev\Ide\vs2005\VC\vcvarsall.bat” />

  <!– TIMESTAMPS –>
        <tstamp>
                <format property=“TheStartTime” pattern=“dd-MM-yyyy hh:mm aa” />
        </tstamp>

 
  <!– DEFAULT RUN TARGETS  –>
  <target name=“ApacheBuild” depends=“startme,cleanUp,setup,compile,zipbin” >
    <echo message=“– Ending=${TheStartTime}” />
    <echo message=“– Done !” />
  </target>

 
  <!– Startup –>
  <target name=“startme” >
    <echo message=“– Start startme:” />
    <echo message=“– ${TheStartTime}” />
    <mkdir dir=“${buildDir}” />
  </target>

  <!– Fails on cleanup, as it might be clean already, or never created –>
        <target name=“cleanUp” >
    <echo message=“– Start cleanup:” />
                <delete dir=“${buildDir}” failonerror=“yes”/>
    <delete file=“${basedir}/${ApacheBin}” />
        </target>

  <!– Unzip and copy –>
  <target name=“setup” >
    <echo message=“– Start setup:” />
   
    <!– make sure the build dir is present –>
    <mkdir dir=“${buildDir}” />
   
    <!– Apache source –>
    <unzip src=“${ApacheSource}” dest=“${buildDir}”/>
   
    <!– OpenSsl source –>
    <gunzip src=“${OpenSslSourceGz}”/>
    <untar src=“${OpenSslSourceTar}” dest=“${buildDir}”/>
    <!– Add openssl to source dir –>
    <move todir=“${buildLibOpenSslDir}”>
      <fileset dir=“${buildDir}/${OpenSslTop}”/>
    </move>

    <!– Zlib source –>
    <gunzip src=“${ZlibSourceGz}”/>
    <untar src=“${ZlibSourceTar}” dest=“${buildDir}”/>
    <!– Add Zlib to source dir –>
    <move todir=“${buildLibZlibDir}”>
      <fileset dir=“${buildDir}/${ZlibTop}”/>
    </move>
    <!– Add zlib lib to source dir as well –>
    <copy file=“${zipLibDir}/zdll.lib” todir=“${buildLibZlibDir}”/>

  </target>
 
 
 
  <!– Compile packages  –>
  <target name=“compile” >
    <echo message=“– Start compile:” />

    <!– Vs2005 environment variables –>
    <exec executable=“cmd”>
      <arg value=“/c”/>
      <arg value=“${VsEnvir}”/>
    </exec>

    <!– Build OpenSsl –>
    <echo message=“– Start compile OpenSsl:” />
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}” >
      <arg value=“/c”/>
      <arg value=“perl Configure VC-WIN32”/>
    </exec>
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}”>
      <arg value=“/c”/>
      <arg value=“ms\do_masm”/>
    </exec>
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}”>
      <arg value=“/c”/>
      <arg value=“nmake -f ms\ntdll.mak”/>
    </exec>
    <!– Test OpenSsl –>
    <echo message=“– Start test OpenSsl:” />
    <exec executable=“cmd” dir=“${buildLibOpenSslDir}/out32dll”>
      <arg value=“/c”/>
      <arg value=“..\ms\test”/>
    </exec>

   
    <!– Build Apache with the default localhost, port 80 –>
    <echo message=“– Start compile Apache:” />
    <exec executable=“cmd” dir=“${buildDir}/${ApacheSourceTop}”>
      <arg value=“/c”/>
      <arg value=“nmake /f Makefile.win SERVERNAME=localhost PORT=80 INSTDIR=${buildDir}/../${ApacheName} installr”/>
    </exec>

  </target>

  <!– Zip up the Apache  –>
  <target name=“zipbin” >
    <zip
      destfile=“${basedir}/${ApacheBin}”
      basedir=“${buildDir}/../${ApacheName}”
    />

  </target>

</project>

Build .Net 3.5 code with Nant, MsBuild on build server without installing VS2008

If you don’t have enough space to install Visual Studio 2008 on your build machine to build .Net 3.5 solution you can do the following. Most likely you will run into the same obstacles as I did, maybe others as well.

First download Windows SDK for Windows Server 2008 and .NET Framework 3.5
http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE331CDC&displaylang=en

When you install you can skip the documentation and samples, it will bring the install down from 2.4GB ! down to about 525MB, not bad.


If you get the following error when you set the framework to Net-3.5 from Nant

System.NullReferenceException: Object reference not set to an instance of an object. at NAnt.Core.FrameworkInfo.get_Version()

You have a certain version of Nant around 0.86 that has old version of the path for the SDK. In your nant.exe.config under net-3.5 look for this section

<project>
    <readregistry
        property=“installRoot”
        key=“SOFTWARE\Microsoft\.NETFramework\InstallRoot”
        hive=“LocalMachine” />

    <readregistry
        property=“sdkInstallRoot”
        key=“SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\WinSDKNetFxTools\InstallationFolder”
        hive=“LocalMachine”
        failonerror=“false” />

    <property name=“frameworkDirectoryV35” value=“${path::combine(installRoot, ‘v3.5’)}” />
    <fail if=“${not(directory::exists(frameworkDirectoryV35))}”>The Framework directory for .NET 3.5 does not exist.</fail>
    <property name=“referenceV35” value=“${environment::get-folder-path(‘ProgramFiles’)}/Reference Assemblies/Microsoft/Framework/v3.5” />
    <fail if=“${not(directory::exists(referenceV35))}”>The Reference Assemblies directory for .NET 3.5 does not exist.</fail>
</project>

change the sdkInstallRoot key v6.0A value to the following
key=”SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.1\WinSDKNetFxTools\InstallationFolder”


If you get the following as well
MY.Web.csproj(364, 11): error MSB4019: The imported project “C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

No problem, copy the content of your v9.0 directory from your dev box under C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0 to your build server, these are just configuration files.


Then if your using the Microsoft test extensions you might get this one as well
App\DataAccess\CaseDataAccessTest.cs(5, 17): error CS0234: The type or namespace name ‘VisualStudio’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)

We will simply solve this one by copying the MS test dll’s from the dev machine and install them in the Gac on the build machine.
C:\tmp>gacutil /i Microsoft.VisualStudio.QualityTools.Resource.dll
C:\tmp>gacutil /i Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll


Now you should be good to go and ready to build on the build server without the heavy VS2008 install.