Archive for August, 2008

This is a continuation of B&R and CI post.Do read part1, part2 and part3.

In this Post we ll discuss common extensibility task we might need for msbuid and nant script in our CI.

Extensibility points

There are so many other tasks that can be integrated to the msbuild/NAnt build scripts. They can be used as per the requirements.

MSBuild Extensions

 

Setting up the iis server, physical and virtual directory path’s creation, copying code to the virtual directory

Task for setting up the iis server, creating a physical path and virtual path in the iis server and copying code to the virtual directory path.

 

<PropertyGroup>

<InetpubWwwrootDirectoryPhysicalPath>C:\Inetpub\wwwroot</ InetpubWwwrootDirectoryPhysicalPath>

    <VirtualDirectoryName>RiskManager.Server.Web</ VirtualDirectoryName>

</PropertyGroup>

 

<Target Name=”Restart_IIS”>

    <Message Text=”Restarting IIS……”/>

    <Exec Command=”iisreset.exe /restart”/>

    <Message Text=”Deployed..access the application “/>

</Target>

 

<Target Name=”CreatePhysicalFolder”>

<Exec Command=”$(InetpubWwwrootDirectoryPhysicalPath )\$( VirtualDirectoryName)”/>

</Target>

   

<Target Name=”CreateVirtualDirectory”>

            <Message Text=”Creating virtual directory …”/>

<WebDirectoryCreate VirtualDirectoryName=”$( VirtualDirectoryName)”

                VirtualDirectoryPhysicalPath=”$( InetpubWwwrootDirectoryPhysicalPath)” />

<Message Text=”[Build Message] :Virtual directory created successfully”/>

</Target>

 

<Target Name=”CopyCcodeToVirtualDirectory”>

<Exec Command=”copy release/app/urApp.Web\*.* $(InetpubWwwrootDirectoryPhysicalPath)\$(VirtualDirectoryName)”/>

</Target>

 

Sandcastle task

Sandcastle task which creates the corresponding help files for a particular assembly.

 <PropertyGroup>
<DOUBLE_QUOTES>%22</DOUBLE_QUOTES>
<DocFolder>$(MSBuildProjectDirectory)</DocFolder>
<SandCastleHFBProject>BuildingSolution.shfb</SandCastleHFBProject>
<SandCastleHFBPath>C:\Program Files\EWSoftware\Sandcastle  Help File Builder\</SandCastleHFBPath>
<SandCastleHFBCmd>$(SandCastleHFBPath)SandcastleBuilderConsole.exe</SandCastleHFBCmd>
</PropertyGroup>

<Target Name=”ClenUpSHFBFiles”>
<CreateItem Include=”$(MSBuildProjectDirectory)\doc\*.*”>
<Output TaskParameter=”Include” ItemName=”OldSHFBFiles”/>
</CreateItem>
<Delete Files=”@(OldSHFBFiles)”/>
<RemoveDir Directories=”$(MSBuildProjectDirectory)\doc” />
</Target>

<Target Name=”SandcastleHelpFileBuilder” DependsOnTargets=”Compile”>
<Exec Command=”$(DOUBLE_QUOTES)$(SandCastleHFBCmd)$(DOUBLE_QUOTES) $(DOUBLE_QUOTES)$(MSBuildProjectDirectory)\$(SandCastleHFBProject)$(DOUBLE_QUOTES)” />
</Target>

 

NDepend Tasks:-
NDepend is a sort of dependency walker tool which help out to analyze the complexities of managed assemblies. This tool will help to show the dependencies between them.

<PropertyGroup>
<DOUBLE_QUOTES>%22</DOUBLE_QUOTES>
<NDependProjectFile>NDependProject.xml</NDependProjectFile>
<NDependPath>C:\Program Files\NDepend\</NDependPath>
</PropertyGroup>

<Target Name=”ClenNDependFiles”>
<CreateItem  Include=”$(MSBuildProjectDirectory)\NDependOut\**\*.*”>
<Output TaskParameter=”Include”  ItemName=”OldNDependFiles”/>
</CreateItem>
<Delete Files=”@(OldNDependFiles)”/>
<RemoveDir  Directories=”$(MSBuildProjectDirectory)\NDependOut” />
</Target>

<Target Name=”NDepend”>
<Exec  Command=”$(DOUBLE_QUOTES)$(NDependPath)NDepend.Console.exe$ (DOUBLE_QUOTES)  $(DOUBLE_QUOTES)$(MSBuildProjectDirectory)\$(NDependProjectFile)$(DOUBLE_QUOTES)” />
</Target>

 

MSBuild Task written in C# script

Writing a task which can invoke a static c# method embedded in the script file..

 

<PropertyGroup>

  <Code>

    <![CDATA[

                                    public static void ScriptMain() {

                                                List<string> list = new List<string>();

                                                list.Add(“This target”);

                                                list.Add(“is written”);

                                                list.Add(“in C#”);

                                                Console.WriteLine(“C# scripting in msbuild”);

                                                foreach(string s in list)

                                                {

                                                  Console.WriteLine(s);

                                                }

                                    }

                                    ]]>

  </Code>

</PropertyGroup>

 

<Target Name=”Script”>

  <Script Language=”C#” Code=”$(Code)” />

</Target>

 

Different build scenarios
Even though the msbuild/nant tasks are useful in the process of continuous integration, in the actual practice all of these tasks may not be required in different build scenarios. For example in the case of a developer build, iis tasks and Svn Checkout will not have much importance. But for full build or nightly build it has most importance and should be one of the preliminary tasks to perform. Here lists some of such scenarios.

Developer Build
List of tasks required are
Cleanup compilation output files, Compile
Cleanup Unit testing output files, Unit Testing
Cleanup Code coverage output files, Code coverage
Cleanup Code quality output files, Code quality
Database creation and population of data(such as adding tables, views, stored procedures etc using sql)
Svn Clean up, Svn checkout, Versioning, NDepend, Sandcastle, QTP etc are not required here.

QA Build
List of tasks required are
Svn Clean up, Svn checkout, Versioning
Cleanup compilation output files, Compile
Cleanup Unit testing output files, Unit Testing
Cleanup Code coverage output files, Code coverage
Cleanup Code quality output files, Code quality
Database creation and population of data(such as adding tables, views, stored procedures etc using sql)
QTP
NDepend, Sandcastle etc are not required here.

Full build and Nightly build
List of tasks required are
Svn Clean up, Svn checkout, Versioning
Cleanup compilation output files, Compile
Cleanup Unit testing output files, Unit Testing
Cleanup Code coverage output files, Code coverage
Cleanup Code quality output files, Code quality
Database creation and population of data(such as adding tables, views, stored procedures etc using sql)
QTP
NDepend
Sandcastle
All the tasks are required here.

Different such scenarios can be achieved by providing some main targets with names reflecting the build scenario and invoking required targets from there. As an example a <FullBuild> target will look like this.

<Target Name=”FullBuild”>
<CallTarget Targets=”Version” />
<CallTarget Targets=”SvnCleanup” />
<CallTarget Targets=”CodeSvnGet” />
<CallTarget Targets=”Clean” />
<CallTarget Targets=”Compile” />
<CallTarget Targets=”ClenUpTestFiles” />
<CallTarget Targets=”Test” />
<CallTarget Targets=”ClenUpCoverageFiles” />
<CallTarget Targets=”Coverage” />
<CallTarget Targets=”ClenUpFxcopFiles” />
<CallTarget Targets=”Reporting” />
<CallTarget Targets=”Documentation” />
<CallTarget Targets=”ClenUpSHFBFiles” />
<CallTarget Targets=”SandcastleHelpFileBuilder” />
<CallTarget Targets=”ClenNDependFiles” />
<CallTarget Targets=”NDepend” />
<CallTarget Targets=”Create_db” />
<CallTarget Targets=”Create_tables” />
<CallTarget Targets=”Create_views” />
<CallTarget Targets=”Create_procs” />
</Target>
Similarly we can create different main targets such as <DeveloperBuild>, <QABuild>, <NightlyBuild> etc.

 Tips and Tricks
• How to use VS.NET 2005 intellisense to create/edit NAnt build scripts?
1. Copy the schema file “nant.xsd” to “C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas”. This schema file will be available under “NAnt Install path\schema\”
2. Set the name space in your build file as shown below:
<project name=”BuildingSolution” default=”help” xmlns=”
http://nant.sf.net/release/0.85/nant.xsd“>
3. Use the VS IDE to edit the build files with intellisense support

 

In next Post we ll discuss other frmaeworks and different links and couple of useful tools on CI processes as well as I will try to point out the comparision between VSTS ,custom CI,openSource ve PAID tools.

This post is a Continuation from earlier posts Where as I started with what CI is and What Toolset you might need .I would recommend you to read the Part1and Part2 before  continue reading this post.

The goal for this post is to create a CI using NANT instead of Msbuild:-

In the target list only one target has been added, which is the build target. This target is responsible for calling other tasks through <call target=”” /> command. These targets are invoked in the order they are written, so the script should take care of the dependencies between the tasks while calling them sequentially. The corresponding script is listed below.

<target name=”Mainbuild” description=”compiles the source code”>

    <call target=”svn.cleanup”/>    <call target=”code.svn.get”/>    <call target=”clean”/>    <call target=”compile”/>    <call target =”create_db”/>

    <call target =”create_tables”/>    <call target =”create_views”/>    <call target =”create_procs”/>    <call target=”runUnitTests”/>

    <call target=”runFxCop”/>    <call target=”RunCodecoverage”/> 

</target>

Here different targets such as “svn.cleanup”, “compile” etc are getting called as per the dependency among them.

Clean up the source control(svn)

Invoking the Svn Cleanup on a particular project, which is in svn source control.

<property name = “svn.exe.physical.path” value=”c:\program       files\subversion\bin\svn.exe” />

<property name = “Svn.Update.Path”     value=”C:\BuildingSolution”/>

<target name=”svn.cleanup”>

<exec program=”${svn.exe.physical.path}” commandline=’ cleanup “${Svn.Update.Path}”‘ failonerror=”false” verbose=”true” />

</target>

Get latest code from the source control(svn)

Getting the latest code for a particular project using Svn Checkout.

<property name = “svn.uri”        value=”Trunk URL ” />

<property name = “Svn.Update.Path”     value=”C:\BuildingSolution”/>

<target name=”code.svn.get”>

    <svn-checkout      destination=”${Svn.Update.Path}” uri=”${svn.uri}” verbose=”true” username=”username” password=”password” />

</target>

  Versioning

Creating a task which generates the version.

<asminfo output=”AssemblyInfo.cs” language=”CSharp”>

    <imports>

      <import namespace=”System” />

      <import namespace=”System.Reflection” />

     </imports>

    <attributes>

      <attribute type=”ComVisibleAttribute” value=”false” />

      <attribute type=”CLSCompliantAttribute” value=”true” />

      <attribute type=”AssemblyVersionAttribute” value=”1.0.0.0″ />

      <attribute type=”AssemblyTitleAttribute” value=”My assembly” />

<attribute type=”AssemblyDescriptionAttribute” value=”ur description” />

<attribute type=”AssemblyCopyrightAttribute” value=”ur copyright info />

<attribute type=”ApplicationNameAttribute” value=”myAssembly” />

    </attributes>

    <references>

      <include name=”System.EnterpriseServices.dll” />

    </references>

</asminfo>

Cleanup, Compilation(msbuild)

Compiling the project after cleaning up the previous compilation output files.

In the “compile” target, we are using <msbuild> task to compile the project since compilation through nant for web-based projects are not as successful as msbuild based compilation. See the script snippet below.

<property name=”Build.OutputFolder”   value=”c:\builds\buildingsolution\”/>

<target name=”clean” description=”remove all generated files”>

    <delete>

      <fileset basedir=”${Build.OutputFolder}Latest\”>

        <includes name=”*.*”/>

      </fileset>

    </delete>

</target>

 

<target name=”compile” description=”Compiles using the AutomatedDebug Configuration”>

<loadtasks assembly=”C:\Softwares\nant-0.85-bin\nant-0.85\bin\nant.exe” />

<!–We are using msbuild task for compiling is bcoz nant may not be successfull in building the web applications–>

<msbuild project=”C:\projects\BuildingSolution\BuildingSolution.sln”>

<property name=”Configuration” value=”Debug” verbose=”true”/>

    </msbuild>

</target>

Note: – Though we can compile source code using devenv.exe, it requires Visual Studio to be installed on the machine. This is the reason why we are using MSBuild instead.

 Cleanup, Unit Testing(NUnit)

Unit testing the project after cleaning up the previous unit test log files.

<property name=”Build.OutputFolder”   value=”c:\builds\buildingsolution\”/>

<target name=”cleanuptestfiles”>

    <delete>

      <fileset basedir=”${Build.OutputFolder}buildlogs\”>

        <includes name=”test.xml”/>

      </fileset>

    </delete>

</target>

<target name=”runUnitTests” description=”Runs unit tests on       specified dlls”>

              <nunit2 failonerror=”false” verbose=”true”>

<formatter outputdir=”${Build.OutputFolder}\” usefile=”true” type=”Xml” extension=”.xml”/>

               <test>

<assemblies basedir=”C:\BuildingSolution\BuildingTest\bin\Debug”>

                            <includes name=”*Test.dll”/>

                          </assemblies>

              </test>

  </nunit2>

</target>

Cleanup, Code coverage(NCover)

Code coverage tool invocation for checking the code coverage statistics after cleaning up the previous code coverage log files.

<property name=”Build.OutputFolder”   value=”c:\builds\buildingsolution\”/>

<target name=”cleanupcover”>

    <delete>

      <fileset basedir=”${Build.OutputFolder}buildlogs\”>

        <includes name=”coverage.xml”/>

      </fileset>

    </delete>

</target>

<target name=”RunCodecoveragefiles” description=”Generate code coverage using NCover”>

    <exec program=”C:\Program Files\NCover\NCover.Console.exe”>

      <arg value=”//w &quot;C:\projects\BuildingSolution&quot;” />

<arg value=”//x &quot; ${Build.OutputFolder}buildlogs \coverage.xml&quot;” />

<arg value=”&quot;C:\projects\BuildingSolution\BuildingUI\bin\Debug\BuildingUI.exe&quot;” />

      <arg value=”BuildingTest.dll” />

    </exec>

</target>

Cleanup, Code quality(FxCop)

Code quality tool invocation for checking the quality and coding standards of the project after cleaning up the previous code quality log files.

<property name=”Build.OutputFolder”   value=”c:\builds\buildingsolution\”/>

<target name=”cleanupfxcopfiles”>

    <delete>

      <fileset basedir=”${Build.OutputFolder}buildlogs\”>

        <includes name=”fxcop-results.xml”/>

      </fileset>

    </delete>

</target>

<target name=”runFxCop”>

<exec program=”C:\Program Files\Microsoft FxCop 1.35\fxcopcmd.exe”

      commandline=”/p:${nant.project.basedir}\${nant.project.name}.fxcop /o:${Build.OutputFolder}\fxcop-results.xml” failonerror=”false”/>

</target>

·                     Database creation and population of data(such as adding tables, views, stored procedures etc using sql)

Tasks which execute .sql files to create a database connection; and adding up tables, views and stored procedures to the database.

<property name = “db.server” value=”UrDBServer” />

<property name = “db.instance” value=”\SQLEXPRESS” />

<property name = “db.user” value=”sa” />

<property name = “db.password” value=”sa” />

<property name = “db.name” value=”BuildingSolutionDB” />

<target name=”create_db” description=”Create DB”>                

              <echo message=”Creating Database….”/>

              <exec program=”osql.exe” commandline=”-S ${db.server}${db.instance} -U ${db.user} -P ${db.password} -b -n -i Database\createDB.sql” verbose=”true”/>

              <echo message=”Database Created successfully….”/>

</target>

 

<target name=”create_tables” description=”Create Tables”>                    

                        <echo message=”Creating Tables”/>

                        <foreach item=”File” property=”filename”>

                                    <in>

                                                <items>

<include name=”Database\Tables\*.sql”></include>

                                                </items>

                                    </in>

                                    <do>

<regex pattern=”^(?’path’.*(\\|/)|(/|\\))(?’file’.*)$” input=”${filename}” />

<exec program=”sqlcmd” verbose =”true” commandline=’-S ${db.server}${db.instance} -U ${db.user} -P ${db.password} -i “${filename}”‘/>

                                    </do>

                        </foreach>

</target>

 

<target name=”create_views” description=”Create Views”>

    <echo message=”Creating Views”/>

    <foreach item=”File” property=”filename”>

      <in>

        <items>

          <include name=”Database\Views\*.sql”></include>

        </items>

      </in>

      <do>

        <regex pattern=”^(?’path’.*(\\|/)|(/|\\))(?’file’.*)$” input=”${filename}” />

<exec program=”sqlcmd” verbose =”true” commandline=’-S ${db.server}${db.instance} -U ${db.user} -P ${db.password} -i “${filename}”‘/>

      </do>

    </foreach>

</target>

 

<target name=”create_procs” description=”Create Stored Procs”>

    <echo message=”Creating Stored Procedures”/>

    <foreach item=”File” property=”filename”>

      <in>

        <items>

<include name=”Database\StoredProcedures\*.sql”></include>

        </items>

      </in>

      <do>

        <regex pattern=”^(?’path’.*(\\|/)|(/|\\))(?’file’.*)$” input=”${filename}” />

<exec program=”sqlcmd” verbose =”true” commandline=’-S ${db.server}${db.instance} -U ${db.user} -P ${db.password} -i “${filename}”‘/>

      </do>

    </foreach>

</target>

  CCNet.Config File:-The Only Chnages here from the MSbuild approach will be ,We ll be calling Nant Task Like the following:-

<tasks>

      <nant>

        <executable>C:\Softwares\nant-0.85-bin\nant-0.85\bin\nant.exe</executable>

        <baseDirectory>C:\BuildingSolution</baseDirectory>

        <buildFile>BuildingSolution.build</buildFile>

        <targetList>

          <target>Mainbuild</target>

        </targetList>

        <buildTimeoutSeconds>1200</buildTimeoutSeconds>

      </nant>

    </tasks>

 

Now That we discussed both Nant as well as Msbuild based approaches,Let discuss few important extensibility points before moving out to tools like CIfactory and TeamCity.In part-4 We ll be covering Extensibilty and in Part-5 we ll be covering CI factory and TeamCity and I will rpovide important links on the Concluding Post.

 

Part4 Link

Part5 Link soon

 

Drop me a line if you found this post useful.

 

This is a continuation of the previous post .If you have not read the previous post,please read it here :-
 
In short we are creating a build,release and CI with .NET  Solution and in this post I will demonstrate how to use MSbuild to perform our build and the CCnet task for the same.
The Solution we ll be using is named BuildingSolution and the working location is placed in C:\BuildingSolution .
My Test folder is BuildingTest and BL folder would be BuildingBL and So on  all inside C:\BuildingSolution.You can structure your Folder as you like but better follow any industry standard for this.
 
The layering for this would be like the following:-
UI[Web and Win both,I have 2 projects 1 Web and another Win]–>Proxy–>Servicehost–>Services–>BL–>DAL–>DB
You can have few more layers for Example :- facade and presentation specific or Service specific layers .Since the intention of this post is around B&R and CI,I am not going to write more about the layering.Only I point I would like to mention is if you might need VS05Sp1 or WebApplication project if you are working with a WebSite and yet like to treat this as Project like .NEt 1.1.
 
Let us now create the msbuild project file and CCNET config  file wich were the essence of our B&R
 
Here is the simplest example how your CCNET.config will look like:-
 

<cruisecontrol>

  <project>

    <name>BuildSolution</name>

    <triggers>

  <intervalTrigger seconds=”900″  buildCondition=”IfModificationExists”/>

    </triggers>

    <sourcecontrol type=”svn”>

      <trunkUrl>ur TrunkUrl here</trunkUrl>

      <workingDirectory>Ur Working Directory here</workingDirectory>

      <executable>c:\program files\subversion\bin\svn.exe</executable>

      <username>Ur username </username>

      <password>Ur passwod</password>

      <autoGetSource>true</autoGetSource>

      <tagOnSuccess>false</tagOnSuccess>

      <timeout>12000000</timeout>

    </sourcecontrol>

 

<!– Note:- If you want to use any other repository like VSS use the ccnetconfig tool to create a SourceControl section for ccnet.config–>

    <triggers />

    <tasks>

      <msbuild>

        <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>

        <workingDirectory>C:\BuildingSolution</workingDirectory>

        <projectFile>webandWin.proj</projectFile>

        <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>

        <targets>MainTarget</targets>

        <timeout>900</timeout>

        <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>

      </msbuild>

    </tasks>

   

<!– Note:- If you want to use any other version like .NET 3.5,please point the appropritae framework’s msbuiild.exe also the Configuration you can keep for Release as well as debug in Build Args–>

    <publishers>

      <merge>

        <files>

          <file>c:\builds\buildingsolution\BuildingTest.dll-results.xml</file>

          <file>c:\builds\buildingsolution\Coverage.xml</file>

          <file>c:\builds\buildingsolution\fxcop-results.xml</file>

        </files>

      </merge>

<!– we are merging the results of Test,Fxcop and CodeCoverage,You can merge other results as and when you want–>

      <xmllogger>

        <logDir>log</logDir>

      </xmllogger>

      <email from=”user1@urcompany.com”              mailhost=”relaymail.urcompany.com”            includeDetails=”TRUE”>

        <users>

          <user name=”user1″ group=”group1″      address=”user1@urcompany.com”/>

        </users>

        <groups>

          <group name=”group1″ notification=”always”/>

        </groups>

            </email>

 

    </publishers>

  </project>

</cruisecontrol> 

 

 

 Now that we saw what our CCNET.config looks like let jump into the MSBUILD project file.Below is the MSBUILD project file tasks wih description:-

 

Continuous Integration using MSBuild and msbuild community tasks

In the msbuild based approach, we will add the executable to be invoked as msbuild.exe in the ccnet.config file. Here we will provide the different targets to be executed in the corresponding .proj file. These targets will get executed in a sequential order.

 

Different steps, tools and associated tasking are as listed below.

Invoking the Svn Cleanup on a particular project, which is in svn source control.

 

<PropertyGroup>

<SvnExePhysicalPath>c:\program files\subversion\bin\svn.exe</SvnExePhysicalPath>

    <SvnUpdatePath>C:\BuildingSolution</SvnUpdatePath>

</PropertyGroup>

 

<Target Name=”SvnCleanup”>

<Exec Command=”$(SvnExePhysicalPath) cleanup $(SvnUpdatePath)”/>

</Target>

Get latest code from the source control(svn)

<PropertyGroup>

<SvnExePhysicalPath>c:\program files\subversion\bin\svn.exe</SvnExePhysicalPath>

    <SvnUpdatePath>C:\BuildingSolution</SvnUpdatePath>

    <SvnUri>ur SVN URI </SvnUri>

</PropertyGroup>

 

<Target Name=”SvnCheckout”>

<Exec Command=”$(SvnExePhysicalPath) checkout $(SvnUri) $(SvnUpdatePath)”/>

</Target>

Versioning

Creating a task which generates the version.

 

<PropertyGroup>

    <Major>1</Major>

    <Minor>0</Minor>

    <Build>0</Build>

    <Revision>0</Revision>

</PropertyGroup>

 

<Target Name=”Version”>

<Message Text=”Version: $(Major).$(Minor).$(Build).$(Revision)”/>

    <AssemblyInfo CodeLanguage=”CS” 

      OutputFile=”Source\MSBuild.Community.Tasks\Properties\AssemblyInfo.cs”

      AssemblyTitle=”MSBuild Community Tasks”

      AssemblyDescription=”Collection MSBuild Tasks”

      AssemblyCompany=”http://msbuildtasks.tigris.org/&#8221;

      AssemblyProduct=”MSBuild.Community.Tasks”

      AssemblyCopyright=” ”     

      ComVisible=”false”

      CLSCompliant=”true”

      Guid=”ur Guid here”

      AssemblyVersion=”$(Major).$(Minor).$(Build).$(Revision)”

      AssemblyFileVersion=”$(Major).$(Minor).$(Build).$(Revision)”

      Condition=”$(Revision) != ‘0’ “/>

</Target>

Cleanup, Compilation(msbuild)

Compiling the project after cleaning up the previous compilation output files.

 

<PropertyGroup>

<BuildOutputFolder>c:\builds\buildingsolution</BuildOutputFolder>

</PropertyGroup>

<Target Name=”Clean”>

    <Exec Command=”del $(BuildOutputFolder)Latest\*”/>

</Target>

 <Target Name=”Compile” DependsOnTargets=”Version”>

    <MSBuild    Projects=”C:\BuildingSolution\BuildingSolution.sln”

             Properties=”Configuration=Debug” />

</Target>

Note: – Though we can compile source code using devenv.exe, it requires Visual Studio to be installed on the machine.

 

Cleanup, Unit Testing(NUnit)

Unit testing the project after cleaning up the previous unit test log files.

 

<PropertyGroup>

<BuildOutputFolder>c:\builds\buildingsolution</BuildOutputFolder>

</PropertyGroup>

 

<Target Name=”ClenUpTestFiles”>

    <Exec Command=”del $(BuildOutputFolder)buildlogs\test.xml”/>

</Target>

 

<Target Name=”Test” DependsOnTargets=”Compile”>

    <NUnit Assemblies=”C:\BuildingSolution\Bui     ldingTest\bin\Release\BuildingTest.dll “

            ToolPath=”C:\Program Files\NUnit 2.4.8\bin”

                        WorkingDirectory=”C:\BuildingSoluti           on”

OutputXmlFile=”$(BuildOutputFolder)buildlogs \test.xml”

            ContinueOnError=”true”>

      <Output TaskParameter=”ExitCode”      ItemName=”NUnitExitCodes”/>

    </NUnit>

</Target>

Cleanup, Code coverage(NCover)

Code coverage tool invocation for checking the code coverage statistics after cleaning up the previous code coverage log files.

 

<PropertyGroup>

<NCoverExe>”C:\Program Files\NCover\NCover.Console.exe”</NCoverExe>

    <WorkingDirectory>”C:\BuildingSolution\BuildingTest\bin\Release”</WorkingDirectory>

    <ProfiledAssemblies>”BuildingTest”</ProfiledAssemblies>

    <LogFile>”Coverage.log”</LogFile>

    <CoverageHtmlDirectory>”C:\BuildingSolution”</CoverageHtmlDirectory>

<AppToProfileExe>”C:\Program Files\NUnit 2.4.8\bin\nunit-console.exe”</AppToProfileExe>

    <AppToProfileArgs>”BuildingTest.dll”</AppToProfileArgs>

    <BuildOutputFolder>c:\builds\buildingsolution</BuildOutputFolder>

</PropertyGroup>

 

<Target Name=”ClenUpCoverageFiles”>

<Exec Command=”del $(BuildOutputFolder)buildlogs\coverage.xml”/>

</Target>

 

<Target Name=”Coverage” DependsOnTargets=”Test”>

<Exec Command=”$(NCoverExe) //w $(WorkingDirectory) //reg //a $(ProfiledAssemblies) //l $(LogFile) //h $(CoverageHtmlDirectory) $(AppToProfileExe) $(AppToProfileArgs)” />

</Target>

Cleanup, Code quality(FxCop)

Code quality tool invocation for checking the quality and coding standards of the project after cleaning up the previous code quality log files.

 

<PropertyGroup>

<BuildOutputFolder>c:\builds\buildingsolution</BuildOutputF   older>

</PropertyGroup>

 

<Target Name=”ClenUpFxcopFiles”>

<Exec Command=”del $(BuildOutputFolder)buildlogs\fxcop-results.xml”/>

</Target>

 

<Target Name=”Reporting” DependsOnTargets=”Compile”> >

<Exec Command=”FxCopCmd.exe   /project:C:\BuildingSolution\Buildi   ngSolution.FxCop        /out: $(BuildOutputFolder)buildlogs \fxcop-          results.xml” WorkingDirectory=”C:\Program Files\Microsoft             FxCop 1.35″ />

</Target>

 Database creation and population of data(such as adding tables, views, stored procedures etc using sql)

Tasks which execute .sql files to create a database connection; and adding up tables, views and stored procedures to the database.

 

<PropertyGroup>

    <dbserver>ur Server</dbserver>

    <dbinstance>\SQLEXPRESS</dbinstance>

    <dbuser>dbusername</dbuser>

    <dbpassword>dbpassword</dbpassword>

    <dbname>BuildingSolutionDB</dbname>

 </PropertyGroup>

 

<Target Name=”Create_db” DependsOnTargets=”Reporting”>

    <Exec Command=”osql.exe -S $(dbserver)$(dbinstance) -U $(dbuser) -P $(dbpassword) -b -n -i C:\BuildingSolution\Database\createDB.sql” />

</Target>

 

<!–This is a try to iterate through the sql files as in nant, but was unsuccessful–>

<ItemGroup>

<tablesqlfiles Include=”C:\BuildingSolution\Database\Tables\*.sql” />

</ItemGroup>

<ItemGroup>

<viewssqlfiles Include=”C:\BuildingSolution\Database\Views\*.sql” />

</ItemGroup>

<ItemGroup>

<procssqlfiles Include=”C:\BuildingSolution\Database\StoredProcedures\*.sql” />

</ItemGroup>

 

<Target Name=”Create_tables” DependsOnTargets=”Create_db”>

    <Message Text=”Creating Tables”/>

    <Message Text=”Iterate for each item (for-each):  %(tablesqlfiles.Identity)”/>

<Exec Command=”sqlcmd -S $(dbserver)$(dbinstance) -U $(dbuser) -P $(dbpassword) -i %(tablesqlfiles.Identity)”/>

</Target>

 

<Target Name=”Create_views” DependsOnTargets=”Create_tables”>

    <Message Text=”Creating Views”/>

    <Exec Command=”sqlcmd -S $(dbserver)$(dbinstance) -U $(dbuser) -P $(dbpassword) -i %(viewssqlfiles.Identity)”/>

</Target>

 

<Target Name=”Create_procs” DependsOnTargets=”Create_views”>

    <Message Text=”Creating Stored procedures”/>

    <Exec Command=”sqlcmd -S $(dbserver)$(dbinstance) -U $(dbuser) -P $(dbpassword) -i %(procssqlfiles.Identity)”/>

</Target>

 

 

Once you have this ready ,you can now browse to your CCNET ,using http://urbuildserver/ccnet and See the Dashboard buildign your solution with each Change in the codebase in Source control repository.The Next post We will discuss NANT based approach and extensibility as well as other tools and frameworks commonly used:-

 

Part1 Link  Read part3. ,Part4 as well

 

Drop me  a line if you found this post useful.

 

 

 

A well defined Build,Release and CI is a must for any BIG enterprise Project.Its further becomes  utmost important for any agile development process.There are lot of approaches and you can find lot of  articles ,products ,tools once you search on the net .Since I found there are so many tools and processes a developer or architect or any Enterprise needed to be aware of ,Through this post  I am  trying to simplify the learning and also trying to make this post a simple yet effective learing for  newbies.The root of the problem and solution of a well defined B&R and CI applied to any language and technology ,Yet to cut the scope this post will be mostly around .NET and Microsoft technologies.
 
For Continous integration concepts I would like to point out the great post made by martin fowler .A must read for anyone who is trying to understand the theoritical aspects of CI.Read it here.
 
So,What all we need,What are the tool set we use for CI?The comon components you need are :-
 
1.SourceControl Repository[From where you get and to which you submit your code.Few widely used and common tools are VSS,Subversion[SVN],CVS,Perforce etc.
2.Versioning of your codebase
3.Cleanup the repository and outputs
4.Compile your code using build tools like NANT or MSBUILD [generally .NET code but can be more complicated to Build your DB,Add custom code for your specific tasks like adding to gac and signing assemblies ,create your config entries etc
5.UnitTest :- [Few Common and most used are Xunit,Nunit,MBunit,CsUnit,QuickUnit and VSTS unittest]
6.CodeQuality Checks [Fxcop ,Ndepend]
7.Code Coverage tools-VSTS codecoverage ,Ncover,PartCover etc;
8.Documentation support[Sandcastle and Ndoc ]
9.A dashboard and services  for CI tools [CC.NET,Draco.NET ,CIfactory,Teamcity,Clover.Net etc and at client side Cctray or other notification etc]
10.Release process[Creation of msi,IIS Virtual Directory and copying the Files,creation of ZIP packages
 
You can see the scope and toolset already is pretty large and once you consider automation testing framework like QTP automation and mocking framework as well as custom plugins into your process the scope increases further.Believe me ,you ask any management of any large Enterprise projects and the scope has to be settled down at some point and you still have a lot of scope for the improvements.
 
In the following post I will Demonstrate CI with the following tools:-
 
SVN Subversion
Subversion (SVN) is a version control system . It is used to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS).
Download link :
http://subversion.tigris.org/

Tortoise SVN Client
TortoiseSVN is a Subversion client, implemented as a Microsoft Windows shell extension. It is free software released under the GNU General Public License.
Download link :
http://tortoisesvn.net/downloads
NAnt
NAnt is a free software (open source) software tool for automating software build processes. It is similar to Apache Ant, but targeted at the .NET environment rather than Java.
Download link :
http://sourceforge.net/projects/nant
NAntContrib
NAntContrib is the project for tasks and tools that haven’t made it into the main NAnt distribution yet. But these are the additional set of tasks which will help script writers to have the flexibility of adding new set of tasks to their NAnt scripts. These tasks include tasks for invoking different third party tools.
To use the NAntContrib, copy the NAntContrib bin’s contents to the NAnt bin.
Download link :
http://sourceforge.net/projects/nantcontrib/
NUnit
NUnit is an open source unit testing framework for Microsoft .NET. It serves the same purpose as JUnit does in the Java world, and is one of many in the xUnit family.
Download link : http://www.nunit.org/index.php
.NET Framework 2.0 or above
The Microsoft .NET Framework is a software technology that is available with several Microsoft Windows operating systems. It includes a large library of pre-coded solutions to common programming problems, a runtime or virtual machine that manages the execution of programs written specifically for the framework, and a set of tools for configuring and building applications. The .NET Framework is a key Microsoft offering and is intended to be used by most new applications created for the Windows platform.
FxCop
FxCop is a free static code analysis tool from Microsoft that checks .NET managed code assemblies for conformance to Microsoft’s .NET Framework Design Guidelines. Unlike the Lint programming tool for the C programming language, FxCop analyzes the compiled object code, not the original source code.
Downloadlink:
http://www.microsoft.com/downloads/details.aspx?familyid=3389F7E4-0E55-4A4D-BC74-4AEABB17997B&displaylang=en
NCover
Code coverage analysis is a measurement that is taken on running program code reporting how much of that code was executed. Specifically, code coverage usually tells you how many times each line of code was executed. There are various forms of coverage metrics, such as function coverage, sequence point coverage, statement coverage and branch coverage. NCover is a tool that analyzes running code and is able to determine whether code was visited or unvisited while running. Visited code is code that was executed during the running of a process, and unvisited code is code that was not executed.
Download link :
http://www.ncover.com/
MSBuild Community
MSBuild is an XML-based build engine and a tool that has been developed with customizability and extensibility in mind from its conception. By using MSBuild, you can change how your projects are built, creating customizations to fit your needs. This gets installed with the .NET runtime. MSBuild community tasks
http://msbuildtasks.tigris.org/  are the set of tasks independently developed and not part of the main task group of Msbuild. But these tasks are helpful in integrating third party tools into the build process.
CruiseControl.NET
This is one of the best tools which help the continuous integration for the rapid project development. This tool can give host many of the existing .NET based third party tools like NCover, FxCop, NUnit etc to help out continuous integration.
Download link :
http://ccnetlive.thoughtworks.com/

CCnetConfig
can be used to generate templates for different tasks. This is a better way of adding tasks to the ccnet.config file.
Download link :
http://ccnetconfig.org/
SandCastle Help File Builder
Sandcastle produces accurate, MSDN style, comprehensive documentation by reflecting over the source assemblies and optionally integrating XML Documentation Comments. It has few problems like it is command line based and has no GUI front-end, project management features, or an automated build process like those that you can find in NDoc. Sandcastle Help File Builder will fill in the gaps and provide some of the missing NDoc-like features, as well as provide graphical and command line based tools to build a help file in an automated fashion.
Download link: http://www.codeplex.com/SHFB/Release/ProjectReleases.aspx?ReleaseId=10445
NDepend
NDepend is a tool that simplifies managing a complex .NET code base. Architects and developers can analyze code structure, specify design rules, plan massive refactoring, do effective code reviews and master evolution by comparing different versions of the code with the help of this tool.
Download link:
http://www.ndepend.com/ndependdownload.aspx
CCTray
CCTray is an optional utility for use with the CruiseControl.NET Continuous Integration server. It provides feedback upon build progress, and allows control over some of the server’s operations. It can Monitor multiple projects on many build servers, Identify the build status with a glance to the system tray, See the status of individual builds in a popup window, Audio/Visual feedback upon completion of builds, indicating success or failure, Force a build from any PC (when the CruiseControl.NET server is sleeping)
Download link :
http://ccnetlive.thoughtworks.com
 
 
In this post we will be using both NANT based approach in case you already have spent significant time in NANT as well as MSbuild based approach which I would recommend for future .Further to that I would like to mention that you can compile using only NANT but that has certain limitations which nant contib try to iliminate .Further to that we can always use msbuild task for nant[msbuild task inside nant script to compile].Similarly you can compile your code using the DEVEnv.exe itself but that does need VS installed in your build server.
Continuous Integration Process
The approach is to introduce a ccnet.config file which will invoke either the MSBUILD or the NAnt based scripts for automated build, unit test, coverage etc. The ccnet.config file is executed through the ccnet.exe. In this configuration file, steps to connect to the source control and tasks to invoke the msbuild script file(.proj) or the NAnt script file(.build) is added. This file could contain even <email> task to be executed on completion of the build success/failure. The continuous integration steps can be listed out and invoked through
http://localhost/ccnet .The .proj/.build file which is written in msbuild/nant script can host different tasks like clean, compile, unit test(NUnit), code coverage(NCover), coding standards and code quality checking(fxcop) etc.

We will continue with the script in next post.Please watchout MSBUILD based approach in Part-2 and NAnt based approach in part-3 as well as I will also post some readymade framework and tools which were quite popular like TeamCity http://www.jetbrains.com/teamcity/  , Watin  http://watin.sourceforge.net/ ,FinalBuilder http://finalbuilder.com/and Cifactory http://cifactory.org/joomla/ in future posts.I will also discuss VSTS and the pros and cons of going the VSTS route vs the OpenSource Route in future post.

Read part2 ,part3. ,Part4