Posts Tagged ‘NAnt’

Automating MS CRM Deployment With NAnt – Sample Build Script

October 22, 2010 2 comments

Here is a sample build script to deploy plugins, backup and deploy customisations to MS CRM Server.

It uses the MSCRM Extensions Project I developed on CodePlex. You can get it here. Hope you enjoy this.

<?xml version="1.0" ?>
<project name="CRMPlugins" default="compile" xmlns="">
  <property name="compile.mode" value="Debug" unless="${property::exists('compile.mode')}" />
	<property name="build.dir" readonly="true" value="build" />
  <property name="deploy.dir" readonly="true" value="deploy" />
  <property name="source.dir" value="Source" />
  <property name="dist.dir" readonly="true" value="distribution" />
  <property name="customisations.dir" value="Customisations" />
	<property name="nant.settings.currentframework" readonly="true" value="net-3.5" />
  <property name="" value="Test.Plugins"/>
  <property name="compile.dir" readonly="true" value="${source.dir}\${}\${}\bin\${compile.mode}"/>
  <property name="solution.file" value="${source.dir}\${}\${}.sln"/>
  <property name="plugin.solution.file" readonly="true" value="Plugins.xml"/>
  <property name="dist.file" readonly="true" value=""/>

	<target name="compile">
		<msbuild project="${solution.file}">
			<property name="Configuration" value="${compile.mode}" verbose="false" />
	<target name="full" depends="dist" />

  <target name="export-customisations">
    <crmcustexport crmserver="main.test.local" username="Test" password="Test" domain="Test"
                   file="${customisations.dir}\customisations.xml" org="Test" port="5555"/>

  <target name="publish-customisations">
    <crmcustdeploy crmserver="main.test.local" username="Test" password="Test" domain="Test"
                   file="${customisations.dir}\customisations.xml" org="Test" port="5555"/>

  <target name="build" depends="compile,export-customisations">
    <delete dir="${build.dir}" if="${directory::exists(build.dir)}"/>
    <mkdir dir="${build.dir}" unless="${directory::exists(build.dir)}"/>
    <copy todir="${build.dir}">
      <fileset basedir="${compile.dir}">
        <include name="**\*"/>
        <exclude name="**\*.pdb" />
    <copy todir="${build.dir}" file="${customisations.dir}\customisations.xml"/>
	<target name="dist" depends="build">
    <delete dir="${dist.dir}" if="${directory::exists(dist.dir)}"/>
    <mkdir dir="${dist.dir}" unless="${directory::exists(dist.dir)}"/>
		<zip zipfile="${dist.dir}\${dist.file}">
			<fileset basedir="${build.dir}">
				<include name="**\*" />

  <target name="deploy" depends="dist" >
    <delete dir="${deploy.dir}" if="${directory::exists(deploy.dir)}" failonerror="true"/>
    <mkdir dir="${deploy.dir}" unless="${directory::exists(deploy.dir)}"/>
    <unzip todir="${deploy.dir}" failonerror="true" zipfile="${dist.dir}\${dist.file}" />
    <copy todir="${deploy.dir}" file="${plugin.solution.file}" failonerror="true"/>
    <deployplugins crmserver="main.test.local" username="Test" password="Test" domain="Test"
                   pluginfiledirectory="${deploy.dir}" file="${plugin.solution.file}" org="Test" port="5555"/>

Heres the output. Cool hey.

NAnt 0.86 (Build 0.86.2898.0; beta1; 8/12/2007)
Copyright (C) 2001-2007 Gerry Shaw

Buildfile: file:///c:/Projects/Test/MSCRM/
Target framework: Microsoft .NET Framework 3.5
Target(s) specified: deploy


[msbuild] Build started 22/10/2010 12:44:51 PM.
[msbuild] Project “c:\Projects\Test\MSCRM\Source\Test.Plugi
ns\Test.Plugins.sln” on node 0 (default targets).
[msbuild] Building solution configuration “Release|Any CPU”.
[msbuild] Project “c:\Projects\Test\MSCRM\Source\Test.Plugi
ns\Test.Plugins.sln” (1) is building “c:\Projects\Test\MSCRM\
dWellTechnologies.Plugins.csproj” (2) on node 0 (default targets).
[msbuild] Processing 0 EDMX files.
[msbuild] Finished processing 0 EDMX files.
[msbuild] CoreCompile:
[msbuild] Skipping target “CoreCompile” because all output files are up-to-dat
e with respect to the input files.
[msbuild] CopyFilesToOutputDirectory:
[msbuild] Test.Plugins -> c:\Projects\Test\MSCRM\Source\Test.Plugins\Test.Plugins\bin\Release\Test.Plugins.dll
[msbuild] Done Building Project “c:\Projects\Test\MSCRM\Source\Test\Test.Plugins\Test.Plugi
ns.csproj” (default targets).
[msbuild] Done Building Project “c:\Projects\Test\MSCRM\Source\Test.Plugins\Test.Plugins.sln” (default targets).
[msbuild] Build succeeded.
[msbuild] 0 Warning(s)
[msbuild] 0 Error(s)
[msbuild] Time Elapsed 00:00:00.23


Creating Connection
About to export
Export completed
Export data saved


[delete] Deleting directory ‘c:\Projects\Test\MSCRM\build’.
[mkdir] Creating directory ‘c:\Projects\Test\MSCRM\build’.
[copy] Copying 1 file to ‘c:\Projects\Test\MSCRM\build’.
[copy] Copying 1 file to ‘c:\Projects\Test\MSCRM\build’.


[delete] Deleting directory ‘c:\Projects\Test\MSCRM\distribution’.
[mkdir] Creating directory ‘c:\Projects\Test\MSCRM\distribution’.
[zip] Zipping 2 files to ‘c:\Projects\Test\MSCRM\distribution\’.


[delete] Deleting directory ‘c:\Projects\Test\MSCRM\deploy’.
[mkdir] Creating directory ‘c:\Projects\Test\MSCRM\deploy’.
[unzip] Unzipping ‘c:\Projects\Test\MSCRM\distribution\’ to ‘c:\Projects\Test\MSCRM\deploy’.
[copy] Copying 1 file to ‘c:\Projects\Test\MSCRM\deploy’.
Creating Connection
Removing Existing Installation of Plugin
Registering Plugin Solution
Plugin Solution Registered
Registering Individual Plugins
Registering individual plugins completed
Process completed


Total time: 14.9 seconds.

So its pretty easy.

MS CRM Custom NAnt Tasks

October 8, 2010 Leave a comment

I had to automate CRM deployment and so I wrote some custom NAnt tasks to do so which are part of MS CRM Extensions project located at codeplex at for download.

Still needs a lot of testing but It will definitely be in the next release.

Categories: Development Tags: , , , , ,

NAnt Overriding properties from the console

May 13, 2010 Leave a comment

If you have a property in your project which may change depending on a commandline switch you can override it using the -D:name=value commandline switch.

I the sample below I am overriding the property from the commandline.

<?xml version="1.0" encoding="utf-8"?>
<project name="nantexamples" default="cli-property-overrides" xmlns="">
	<property name="mode" value="default"/>
	<target name="cli-property-overrides">
		<echo message="The value of mode is ${mode}" />

[/Users/blairdavidson/Projects/NantExamples] nant -D:mode=cli-value
NAnt 0.86 (Build 0.86.2898.0; beta1; 8/12/2007)
Copyright (C) 2001-2007 Gerry Shaw

Buildfile: file:///Users/blairdavidson/Projects/NantExamples/
Target framework: Mono 2.0 Profile
Target(s) specified: cli-property-overrides

[property] Read-only property “mode” cannot be overwritten.


[echo] The value of mode is cli-value

BUILD SUCCEEDED – 0 non-fatal error(s), 1 warning(s)

Total time: 0 seconds.


Categories: Development Tags: , , , , , ,

NAnt OS X Build Issues

May 13, 2010 Leave a comment

If you have errors with getting nant build scripts working with mono on Mac OS X add the following to your bashrc file.
export PATH=$PATH:/Library/Frameworks/Mono.framework/Commands/

This will address the following issue:
Expression: ${not pkg-config::exists(’mono’)}

‘pkg-config’ failed to start.


Categories: Development Tags: , , , ,

NAnt Episode 1 – Setup and Compilation

May 11, 2010 Leave a comment

Okay. We are looking at build scripts. We are just going to get setup in this post and getting it building using msbuild.

Lets setup the project structure…
Create a project called NAntBuildDemo, make it a console application for testing purposes. Now create a file called in the same folder as the solution folder.

NAnt has a main project definition which you name and the has whats called targets, basically a group of tasks to run together. With targets you can have them depend on other targets which is important as usually a compile target will depend on a clean target. Sounds like Make of old but its much richer.

Here is the XML…

<?xml version="1.0" encoding="utf-8"?>
<project xmlns="" name="NAntBuildDemo" default="compile">
  <property name="source.dir" value="NAntDemoBuild"/>
  <property name="solution.file" value="NAntDemoBuild.sln" />
  <target name="compile">
    <echo message="Compilation has started: ${framework::get-framework-directory(nant.settings.currentframework)}\msbuild.exe"/>
        program="${framework::get-framework-directory(nant.settings.currentframework)}\msbuild.exe "
        commandline=" ${solution.file}  /nologo /t:Rebuild /p:Configuration=Debug" />
    <echo message="Compilation has completed"/>

You can see we have a also have declared properties. These are basically variable which you can use else where using the ${propertyname} syntax.


Categories: Development Tags: , , , , ,

Is NAnt Dead?

March 12, 2010 Leave a comment
Categories: Development Tags: , , ,