Deploying Applications in VB.NET:
Part 1/2
By Jayesh Jain,
DevArticles
Content Type: Tutorial
Source: DevArticles
Remember back in the good old DOS days when application were small and
just copying those file(s) to the clients machine was all it needed to run?
Unfortunately, that won't work today.
Applications are getting more
sophisticated and complicated everyday, and they need to be installed on the
client's machine with utter care and in the right folders so as to make sure
that every file on the client's computer is accounted and installed properly
and that it does not break any existing application.
When an application is uninstalled,
it should not break any existing applications and it should return the computer
to its original state. Overall, this whole process should be transparent and
simple for the end user.
If you're having problems deploying
your Visual Basic.NET applications, then fret no more! In this article I will
go through the process of creating a deployment for our application in Visual
Basic.NET, which will be a simple one executable file application, which
requires us to install databases, sample files, help files, etc. (in short,
complicated!).
[Note] For all you VB6 or earlier programmers,
there is no Package & Deployment Wizard in VB.NET as the deployment in now
a project type. [End Note]
Unlike the old VB6 deployment kit,
which created script-based setup files, VB.NET creates an installer (.msi)
file, which is more advanced and smarter than the old setup files.
[Note] All application develop under
VB.NET require the .NET framework to be installed on the clients machine. Even
the installer built with VB.NET needs the .NET framework, and hence you need to
install the .NET framework before installing your application. [End Note]
WHAT IS MICROSOFT WINDOWS INSTALLER?
Windows Installer is an installation
and configuration service shipped with Microsoft Windows .NET Server family,
Windows XP, Windows 2000, and Windows Me. The installer is also provided as a
service pack to Microsoft Windows NT version 4.0, Windows 98, and Windows 95.
An installation package contains all
of the information that the Windows Installer requires to install or uninstall
an application or product and to run the setup user interface. Each
installation package includes an .msi file, containing an installation
database, a summary information stream, and data streams for various parts of
the installation. The .msi file can also contain one or more transforms, internal
source files, and external source files or cabinet files required by the
installation.
Windows Installer allows you to roll
back the installation depending on some conditions and returns the computer to
its original state. It also supports self-repair, which could be used to
reinstall missing file(s). Sounds great doesn't it? Well, let's see it in
action!
Creating a Windows Application
Let's create a small Windows
application, which will constantly display the current time on a form. To
implement this, open Visual Studio.Net and create a new Windows application
project, which we will call "MyClock". Click OK:
In the form design window, add a
label control. Change the label controls name property to lbl_time. Add a timer
control to the form. Change the timer controls interval property to 1000.
In the form design window, double
click the form to open the Form1_Load procedure and enter the following line of
code:
Timer1.Enabled = True ' this shall
start the timer
In the form design window, double
click on the timer control to open the Timer1_Tick procedure and type:
lbl_time.Text = TimeOfDay 'This
shall display current time
Our digital clock application is
ready to test. Built the application and run it to make sure our application is
running properly before we start deploying this application.
Adding the Deployment Project
Now that our application is coded
and running fine, we need to think how we are going to distribute the
application. Open the solution explorer, right click the solution and select
Add, then New Project. The same action could be achieved from the File menu as
well.
In the Add New Project window,
select Setup and Deployment Projects from the project types. Also, select Setup
Project from the Templates list. Change the name to MyClockSetup, and select
the location where you want to store your project file(s).
[Hot Tip] Change this location to
the main application project folder. This will ensure that all project and
setup file(s) are created in folders under your main project folder. [End Hot
Tip]
Click OK. The Setup and Deployment
project will be added to your existing project. Clicking OK will also open the
File System window (we will go through that in a moment).
Select the MyClockSetup project from
the Solution Explorer and open the properties window. Change the following
properties:
Manufacturer: devarticles.com
ProductName: MyClock
Title: MyClock
Author: Jayesh
Open the Solution Explorer, right
click on the MyClockSetup project, click View and select File System to open
the File System window.
From the File System on the Target
Machine, right click the Application Folder, click Add and select Project
Output... . In the Add Project Output Group, select
Primary output from the list of options available and finally, click OK.
To run the application on the target
machine, we need to create a shortcut for the application on the user's desktop. To do this, right click on the Primary
Output from MyClock (Active) and select Create ShortCut to Primary Output from
MyClock (Active). Rename this newly created entry to MyClock and drag this
entry (MyClock) to the user's Desktop in the File System on Target Machine Window.
The screenshot below shows you what
everything should look like:
Building the Deployment Project
Open the Solution Explorer and
select the MyClockSetup project. From the Build menu, select Build MyClockSetup
to build our deployment project. This procedure may take a few minutes,
depending upon your machine and will create a Debug folder under the
MyClockSetup folder.
Looking at Installer Files
After the Setup Project is built
without any errors, the following files will be created:
InstMsiA.exe
InstMsiW.exe
MyClockSetup.msi
Setup.exe
Setup.Ini
MyClockSetup.msi is the Windows
Installer file for our application. Setup.exe is the wrapper for the
MyClockSetup.msi, which checks if the correct version of Windows installer is
available before the application is installed.
InstMsiA.exe and InstMsiW.exe are the Windows Installer application file(s), which are
used to support different Windows platforms, such as Windows 95, Windows 98,
Windows ME, Windows NT and Windows 2000.
[Note] Make sure you distribute all
of these files when you deploy your application and always run Setup.exe to
install the application [End Note]
Guess what? You've finished creating
your deployment application! Pat yourself on the back, and let's install our
application.
Installing the Application
To test and run our installer, click
Install from the Project menu. Alternatively, you could also start the
installation by running setup.exe from the installation folder.
Click on the Next button to
continue.
Click next and follow the Screens to
install the application. Once the installation is complete, make sure that a
shortcut is created on the desktop and that it correctly launches our MyClock
application.
Uninstalling the Application
Once you have successfully installed
the application, you can also uninstall it by selecting Uninstall from the
Project menu. You could also uninstall the application from the Add/Remove
Programs list in control panel.
CONCLUSION
I want to mention a few things
before I conclude this article. You can add as many Setup and Deployment
projects in one solution as you want. Each of them can have different settings
and options.
I hope that this introduction to
deployment has shown you how easy and powerful deployment in Visual Basic .NET
is. By adding a few bits and pieces to our project, we saved ourselves from
writing code to install our application -- not to mention uninstalling the same
application.
In the next article we will discover
some more powerful features in deployment projects, such as adding launch
conditions, adding registry entries, prompting users for inputs and much more,
so stay tuned!
If you need
help with your deployment project, then shoot me a message in the DevArticles
VB.NET forum.