Click here to Skip to main content
15,881,938 members
Articles / Operating Systems / Windows
Tip/Trick

Creating an Installer in Visual Studio and Inno Setup

Rate me:
Please Sign up or sign in to vote.
3.88/5 (9 votes)
29 Sep 2015CPOL3 min read 35.8K   15   4
Creating an installer for Windows (Desktop) application in Visual Studio and Inno Setup

Introduction

In this tip, I would like to show how to create an installer for any Windows (Desktop) application from scratch using Visual Studio 2010 and Inno Setup installation system.

Background

Visual Studio supports creating setup projects. These projects are called Visual Studio Installer (.vdproj) and have been available in Visual Studio for a long time.

As they were recently dropped in newest versions, I was forced to find an alternative installation system. I chose Inno Setup which is free (even open source) installation system with many features.

Inno Setup is script based (there is no GUI editor where you can pick up your preferences and generate the installer!) so you need to write everything line by line. This approach is fine (for me) because it allows to completely modify the design, behavior and other aspects of an installer.

As Visual Studio does not natively support editing Inno Setup script files (.iss), I downloaded a Visual & Installer extension which allows to create and edit Inno Setup projects in Visual Studio (2005 - 2015) and offers many features (syntax highlighting, InteliSense, code completion, parameter info, Errors List, Navigation bars, ...)

Get the extension in VS gallery here.

With this extension, it is possible to create a project in Visual Studio which behaves like any other regular project (C++, C#, VB, ...) and offer all features from VS (Batch build, Configuration, Clean, Build, ...) which is really comfortable.

Creating New Project

At first, you need to create a new project. Inno Setup has its own type of project (Inno Setup project :) which generates required files and basic skeleton of your installer. Script file is opened in Visual Studio and you can modify it.

The very minimal skeleton of installer looks like this:

Pascal
[Setup]
AppName=Inno_Setup_Project
AppVersion=1.0
DefaultDirName={pf}\Inno_Setup_Project
DefaultGroupName=Inno_Setup_Project
UninstallDisplayIcon={app}\Inno_Setup_Project.exe
Compression=lzma2
SolidCompression=yes
OutputDir=Output

[Files]
Source: "Script.iss"; DestDir: "{app}"

[Icons]
Name: "{group}\Inno_Setup_Project"; Filename: "{app}\Inno_Setup_Project.exe"

Compiling the Project

The initial script is pretty simple. To compile it, simply hit F5 (or Build, ... depends on your configuration in Visual Studio). You should see progress of Inno Setup compiler in Output window:

After project is compiled, you can run it - launch the resulting .exe file which can be found in Output directory (set via OutputDir directive (usually where project is located):

Pascal
OutputDir=Output

It is good to launch the installer after each compilation. To do it automatically, select Project Properties in Solution Explorer by right clicking the project node and set property. 

Pascal
RunInstaller = Yes

This saves you some time. Also, you can set many other options (command line switches) for Inno Setup compiler here and run tools before and after build which simulates Pre-Build and Post-Build Events from Visual Studio.

Writing the Script

Inno Setup script consists of two parts:

  • First is similar to INI file format: sections [Setup], [Files], [Icons] which contain installer details
  • Second is the [Code] section: you can modify installer behavior here by writing (programming) the installer in Pascal similar language

Visual Studio offers many tools to easily writing the code known as IntelliSense. IntelliSense is simply "Ctrl+Space" thing which speeds up your work in C++, C# or any other language. You can use this feature also in [Code] section to write the script quicker and easier:

If you decide to compile the project now, you receive error (errors, warning and useful messages are shown in Error List window). Double clicking the error line editor jumps to the reported line:

If you solve this error and recompile the script, the resulting installers start:

Points of Interest

Visual Studio offers many other features which make programming easy. Simply try anything you used to do in regular language. Although at this moment some of them are not supported, especially debugging the others are working fine:  IntelliSense Parameter Info, Quick Info, Navigation Bars, Go To (Definition, Declaration, ...), Go To file (Opening files), Code optimizations, Dynamic help, Code Snippets and many others.

Using Visual Studio for editing Inno Setup scripts can be really useful - especially if you have longer scripts with a lot of code.

History

  • September 2015: Version 1 - First public version
  • October 2015: Version 2 - Updated images (wrong paths)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionGood Pin
heinhtataung28-Dec-15 16:03
heinhtataung28-Dec-15 16:03 
Questionimages Pin
eldayan5-Oct-15 5:35
eldayan5-Oct-15 5:35 
Questionpictures don't display Pin
Member 1082439330-Sep-15 6:59
Member 1082439330-Sep-15 6:59 
BugPictures Pin
A Jordison30-Sep-15 2:23
A Jordison30-Sep-15 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.