This document describes what a Setup project is and how they can be created in Visual Studio. C# is a simplified form of C++, which has a Java like syntax. It is very easy to use compared to C++. All the memory management is taken care by .NET

1.1  Installer Object

Any installation activity that is a part of a software installation can be performed by using a System.Configuration.Install.Installer class. The installer class has the following methods which can be overridden

1.1.1  Install

Install method will be called during the software installation. Below is a sample install method.

 

public override void Install(IDictionary stateSaver)

{

base.Install (stateSaver);

Object key = this.Context.Parameters[KEY];

Object name = this.Parameters[NAME];

Object val = this.Parameters[VALUE];

if(key !=null && name != null&& val != null)

{

UpdateRegistry(key.ToString(),  name.ToString(),  val.ToString());

}

}

1.1.2  Commit

Commit method is called once the install method is successfully completed.

public override void Commit(IDictionary savedState)

{

base.Commit (savedState);

Object workDir = this.Context.Parameters[WORKING_DIR];

Object exe = this.Context.Parameters[EXE];

if(workDir != null && exe != null)

{

StartProcess(workDir.ToString(),  exe.ToString());

}

}

1.1.3  Rollback

Rollback method is called to restore the computer if the installation fails.

public void Rollback(IDictionary savedState))

{

base.Rollback (savedState);

UndoInstallation(savedState);

}

private override void UndoInstallation(IDictionary savedState))

{

Object key = this.Context.Parameters[KEY];

Object name = this.Context.Parameters[NAME];

Object exe = this.Context.Parameters[EXE];

if(key != null
&& name != null)

{

DeleteRegistry(key.ToString(),  name.ToString());

}

if(exe != null)

{

StopProcess(exe.ToString());

}

}

1.1.4  Uninstall

This method is called during the uninstall of the software.

public overide void Uninstall(IDictionary savedState)

{

base.Uninstall (savedState);

UndoInstallation(savedState);

}

2  Setup Project

The installation executable can be created by using Setup projects. The Setup project will include
the output from other projects (the exe and dll). The installer object and the methods
defined in section 2.0 are hooked to the installation project by custom actions. The project in
which the installer class is part of, should be included into the setup project.

2.1  Custom Actions

Then custom actions can be created through the custom action view of the setup project. If you right click on the setup project in the solution explorer, and choose view -> custom actions. Separate custom actions can be created under these categories

–      Install

–      Uninstall

–      Commit

–      Rollback

When creating the custom actions, the output from the installer object (project) should be selected. Then the parameters to the custom actions can be passed by setting the value to ‘CustomActionData’ property.

/workingDir=”[TARGETDIR]\” /exe=SWAgent

/key=Software\Microsoft\Windows\CurrentVersion\Run /name=SWAgent /exe=SWAgent

The parameter will be passed as Idictionary to the methods described in section 2