Home > Development > Automating MS CRM Deployment With NAnt – Sample Build Script

Automating MS CRM Deployment With NAnt – Sample Build Script


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="http://nant.sf.net/schemas/nant.xsd">
  <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="plugins.name" value="Test.Plugins"/>
  <property name="compile.dir" readonly="true" value="${source.dir}\${plugins.name}\${plugins.name}\bin\${compile.mode}"/>
  <property name="solution.file" value="${source.dir}\${plugins.name}\${plugins.name}.sln"/>
  <property name="plugin.solution.file" readonly="true" value="Plugins.xml"/>
  <property name="dist.file" readonly="true" value="Test.zip"/>

	<target name="compile">
		<msbuild project="${solution.file}">
			<property name="Configuration" value="${compile.mode}" verbose="false" />
		</msbuild>
	</target>
		
	<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>

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

  <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" />
      </fileset>
    </copy>
    <copy todir="${build.dir}" file="${customisations.dir}\customisations.xml"/>
  </target>
	
	<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="**\*" />
			</fileset>
		</zip>
	</target>

  <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"/>
  </target>
	
</project>

Heres the output. Cool hey.

NAnt 0.86 (Build 0.86.2898.0; beta1; 8/12/2007)
Copyright (C) 2001-2007 Gerry Shaw
http://nant.sourceforge.net

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

compile:

[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\
Source\Test.Plugins\Test.Plugins\Advance
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]
[msbuild] Build succeeded.
[msbuild] 0 Warning(s)
[msbuild] 0 Error(s)
[msbuild]
[msbuild] Time Elapsed 00:00:00.23

export-customisations:

Creating Connection
About to export
Export completed
Export data saved

build:

[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’.

dist:

[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\Test.zip’.

deploy:

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

BUILD SUCCEEDED

Total time: 14.9 seconds.

So its pretty easy.

Advertisements
  1. setty
    February 4, 2011 at 9:44 am

    can you please send me the complete sample code. I want to write a deployment package where no manual intervension is not needed to deploy the code from one environment to another. I mainly need the code to deploy the plugins.

    • February 5, 2011 at 4:35 am

      Get it off mscrmextensions.codeplex.com.

      All there

  1. No trackbacks yet.

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

%d bloggers like this: