Build,Release and Continous Integration-Part4

Posted: August 22, 2008 in Architecture Series

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s