Licensing automated builds with NAnt

Microsoft Visual Studio can license SQL Comparison SDK assemblies automatically. This can also be done without the need to have Visual Studio installed, for instance on a server that automates software builds using the NAnt automated build tool.

Requirements

To license automated builds, the following must be installed on the build server:

1. Create a license on the server

First, a license needs to be created on the server:

  1. Open a command prompt and browse to the SDK folder. For example:

    cd C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin
  2. Create a file named license.txt and open it in a text editor.
  3. In license.txt, add the following:

    RedGate.SQLCompare.Engine.Database, RedGate.SQLCompare.Engine
  4. If you're also using SQL Data Compare, add:

    RedGate.SQLCompare.Engine.Database, RedGate.SQLCompare.Engine
    RedGate.SQLDataCompare.Engine.ComparisonSession, RedGate.SQLDataCompare.Engine
  5. Save the file.

  6. From the command prompt, run the license compiler:

    lc.exe /target:"MyApp.exe" /complist:"license.txt" /i:"C:\Program Files (x86)\Red Gate\SQL Comparison SDK 10\Assemblies\SQL Compare\RedGate.SQLCompare.Engine.dll"
  7. Enter your SQL Comparison SDK serial number.

A SQL_Toolkit_v_x.lic file is created.

2. Configure the build

Next, configure your build:

  1. Create a licenses.licx file in your project and check it into your source control system.
    When your source control provider checks out the source code again, this file will be in your build folder so that the NAnt licensing task can process it.

  2. Add a license task to your NAnt build script, specifying the location of licenses.licx in your build folder and the location of the Red Gate assembly references. For example:

    <target name="licence">
      <license input="${build.dir}MyProject\licenses.licx" target="MyProject.exe" output="${build.dir}MyProject\obj\MyProject.exe.licenses">
       <assemblies>
        <include name="${DataCompare.path}RedGate.SQLCompare.Engine.dll" />
        <include name="${DataCompare.path}RedGate.SQLDataCompare.Engine.dll" />
       </assemblies>
      </license>
     </target>

    This example creates a file called MyProject.exe.licenses in the obj subfolder of your build folder. 

  3. Link the .licenses file into the resources of your output assembly.

    You can't include the .licenses file in the references section of the <vbc> or <csc> task because this resource is already compiled and the <resources> section is for resources that haven't yet been compiled using resgen.exe.
  4. Add an <arg> section inside your <csc> or <vbc> task to force the compiler to include the .licences resource in the compiled assembly:

    <arg line="/res:${build.dir}\MyProject\obj\MyProject.exe.licenses" />

Example build script

This is an example NAnt build script (for a Visual Basic project build) that includes SDK licensing:

 <?xml version="1.0"?>
<project name="Toolkit Licensing Nunit Test" default="build">
 <property name="build.dir" value="c:\NantBuilds\MyProject\" />
 <property name="DataCompare.path" value="c:\program files\red gate\sql data compare 6\" />
 <target name="licence">
  <license input="${build.dir}MyProject\licenses.licx" target="MyProject.exe" output="${build.dir}MyProject\obj\MyProject.exe.licenses">
   <assemblies>
    <include name="${DataCompare.path}RedGate.SQLCompare.Engine.dll" />
    <include name="${DataCompare.path}RedGate.SQLDataCompare.Engine.dll" />
   </assemblies>
  </license>
 </target>
 <target name="build">
  <vbc target="winexe" 
    output="${build.dir}MyProject\bin\Debug\MyProject.exe"
    debug="true"
    main="MyProject.Form1" 
                  optioncompare="text"
                  optionexplicit="true"
                  optionstrict="true"
                  rootnamespace="MyProject"
                  removeintchecks="true"
    verbose="true">
   <sources>
    <include name="${build.dir}MyProject\*.vb" />
   </sources>
   <arg line="/res:${build.dir}\MyProject\obj\MyProject.exe.licenses" />
   <resources dynamicprefix="false" basedir="${build.dir}MyProject\obj" prefix="MyProject">
    <include name="${build.dir}MyProject\*.resx"/>
   </resources>
   <imports>
    <import namespace="RedGate.SQLCompare.Engine" />
    <import namespace="RedGate.SQL.Shared" />
    <import namespace="RedGate.SQLDataCompare.Engine" />
    <import namespace="System.Threading" />
    <import namespace="System.Windows.Forms" />
    <import namespace="Microsoft.VisualBasic" />
              <import namespace="System.Collections" />
                  <import namespace="System.Diagnostics" />
                  <import namespace="System.Drawing" />
   </imports>
   <references>
    <include name="${DataCompare.path}RedGate.SQLCompare.Engine.dll" />
    <include name="${DataCompare.path}RedGate.SQLDataCompare.Engine.dll" />
    <include name="${DataCompare.path}RedGate.SQL.Shared.dll" />
    <include name="Microsoft.VisualBasic.dll" />
    <include name="System.dll" />
    <include name="System.Data.dll" />
    <include name="System.Deployment.dll" />
    <include name="System.Drawing.dll" />
    <include name="System.Windows.Forms.dll" />
    <include name="System.Xml.dll" />
   </references>
  </vbc>
 </target>
</project>

Didn't find what you were looking for?