Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Use NAnt and WinRar to Create a Self Extracting Archive

DZone's Guide to

Use NAnt and WinRar to Create a Self Extracting Archive

· Big Data Zone ·
Free Resource

The open source HPCC Systems platform is a proven, easy to use solution for managing data at scale. Visit our Easy Guide to learn more about this completely free platform, test drive some code in the online Playground, and get started today.

In a recent project, NAnt has been an integral part of creating an installer for a .NET web application with a database back-end. The final stage in creating the ready to deploy executable is packaging the files in a self-extracting archive that extracts and runs the setup. With the help of Winrar and NAnt, that task can be automated. Let's get started.

Requirements:

WinRar SFX options file sample:

; The path to the setup executable
Setup=Setup.msi
; Extract the files to a temporary directory
TempMode
; Use semi-silent mode
Silent=2
; Overwrite any existing files
Overwrite=1
; The title of the SFX archive
Title=Sample Setup
; The text to show initially when the user clicks on the SFX archive (will only matter if using Silent=0)
Text
{
The installer will extract and run the setup
}

NAnt build file sample:

<project name="SampleSFX" default="createSFX" basedir=".">
<description>createSFX task for creating a sample self-extracting installer</description>

<!-- The name of the archive to be created -->
<property name="archiveName" value="SampleSFX" overwrite="false" />

<!-- The target directory from where the build will be invoked -->
<property name="targetDirectory" value="." overwrite="false" />

<!-- The relative path (from the targetDirectory) to directory containing the files to be archived -->
<property name="archiveDirectory" value="<RelativePathToTheDirectoryToArchive>" overwrite="false">

<!-- The mask of the file extensions to be archived -->
<property name="archiveFileMask" value="*.*" overwrite="false" />

<!-- The path to the winrar executable -->
<property name="winrarPath" value="c:\program files\winrar\winrar.exe" overwrite="false" />

<!-- The winrar command line switches for creating the archive -->
<property name="winrarSwitches" value="a -ep -ep1 -r -sfxdefault.sfx" overwrite="false" />

<!-- The name of the sfx options file to use while creating the archive -->
<property name="sfxOptionsFile" value="sfxoptions.txt" overwrite="false" />

<!-- The relative path (from the targetDirectory) to icon file to be used for the created archive -->
<property name="sfxIconFile" value="images\setupIcon.ico" overwrite="false" />

<property name="archiveDirectoryFullPath" value="${path::combine(path::get-full-path(targetDirectory), archiveDirectory)}" overwrite="true" />
<property name="sfxOptionsFileFullPath" value="${path::combine(path::get-full-path(targetDirectory), sfxOptionsFile)}" overwrite="true" />
<property name="sfxIconFileFullPath" value="${path::combine(path::get-full-path(targetDirectory), sfxIconFile)}" overwrite="true" />

<target name="createSFX" description="Creates the self-extracing installer archive">
<exec
basedir="."
program="${winrarPath}"
commandline="${winrarSwitches} -z&quot;${sfxOptionsFileFullPath}&quot; -iicon&quot;${sfxIconFileFullPath}&quot; &quot;${archiveName}&quot; &quot;${archiveDirectoryFullPath}\${archiveFileMask}&quot;"
workingdir="."
failonerror="true" />
</target>
</project>

To run this NAnt task:

  1. Open a command prompt in the targetDirectory you specified in the above build file.
  2. Run the build file with: nant -buildfile:<nameOfTheAboveBuildFile.build>

This will create a single executable file. When the user runs the executable, the setup files will be extracted and the "Setup.msi" (or whatever you specified in the sfx options file) will be executed.

Managing data at scale doesn’t have to be hard. Find out how the completely free, open source HPCC Systems platform makes it easier to update, easier to program, easier to integrate data, and easier to manage clusters. Download and get started today.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}