How to Create Setup file for .NET Windows application?


In this article I have explained about how to create set up file with MS Access Database, Uninstall option, etc. Each steps I have clearly explained in this article with screen shot. First step (create windows application) to last step Uninstall option all are covered in this article.

Description

Create windows application

First we need to create one windows application. Then we create set up file for that application.
Select File -> New -> Project in Visual Studio Standard tool bar.
image1


Give Name for your windows application
image2


Design side
I have design my form with one text box and one DataGridView look like this
image3


In this data grid view I have bind data from MS Access Database. And I use that text box for search records based on name.

Server Side
I have declare variables and connection details in the class


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
using System.Diagnostics;

namespace WindowsSetup
{
public partial class Form1 : Form
{
//You can place your database "Data-directory/Databasefile" under your project bin/Debug folder
static string s=Application.StartupPath + "\\Data\\test.mdb";
static string constr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + s + ";";

OleDbConnection con=new OleDbConnection(constr);
OleDbCommand cmd=new OleDbCommand();
OleDbDataAdapter da=new OleDbDataAdapter();
DataTable dt=new DataTable();

If you want uninstall option for your set up file then write code to get Command Line argument like below.

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//Below code is used to uninstall application

//Get Command Line Arguments
string[] arguments = Environment.GetCommandLineArgs();
foreach (string argument in arguments)
{
if (argument.Split('=')[0].ToLower() == "/u")
{
string guid = argument.Split('=')[1];
string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
ProcessStartInfo si = new ProcessStartInfo(path + "\\msiexec.exe", "/i " + guid);
Process.Start(si);
Close();
Application.Exit();
System.Environment.Exit(0);
}
}

//Load DataGridView first time when form load
refreshGrid();
}

void refreshGrid()
{
string query;
con.Open();
if(textBox1.Text=="")
{
query="select eno,empname,sal from emp";
}
else
{
query = "Select eno,empname,sal from emp where empname like '%" + textBox1.Text + "%'";
}
cmd=new OleDbCommand(query,con);
da = new OleDbDataAdapter(cmd);
dt.Clear();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
//Refresh grid values when each text entered in textbox by user.
refreshGrid();
}
}

That's all we done create one windows application. Compile this application and run it. Output look like below.

output


How to create setup file for .Net Application?

Now we can create set up file for this application with MS Access database.
Go to File - > Add-> New project in the Existing opened Project Visual Studio screen.
image4


Then Select "Setup and Deployment" and right side select "Set up Project" (under visual studio installed templates) in the dialogue box. Give the name for your set up file.
image5


After enter name click Ok button. Screen look like below. Check it that set up file added in your solution explorer (right side)
image6


Now right click on the application folder select Add->Project Output.
image7


After select New pop up appear in that window select "Primary Ouput" Click Ok.
image8


How add MS Access database to the Set up file?

I have placed access database in my application "Data" directory so I need to create directory for same like this in application folder. Right Click of the application folder and choose Add - > New folder and name it for that folder "Data"
image9


Double click that "Data" folder in the application folder to open, now right click and choose Add->File
image10


After select new dialogue box is appear and ask for your database location. Select your database path and click ok in that dialogue box. After added it check your database attached in Application folder look like this.
image11


How to add Desktop Shortcut in setup file?

Select Application folder in File System and right click of the Primary Output file to create short cut for that file.
image12


Rename of that shortcut and cut that shortcut file
image13


After cut that shortcut go to File System (left side) user's desktop, double click that folder and open it and paste that shortcut
image14


If you want change the icon of short cut then select that short cut right click -> choose properties window. In that property window choose icon option to set icon for your desktop shortcut. Make sure if you want add icon in the short cut then you must add that icon in the application folder before.

How to create Shortcut in Programs menu during set up creation?

Select Application folder in File System and right click of the Primary Output file to create short cut
image12


Rename that shortcut same like above steps and Create one new folder in user's Program menu and paste that shortcut under that folder.
image15


How to create uninstall Shortcut in Programs menu?

Select Application folder in File System and right click of the Primary Output file to create short cut
image12


Rename that shortcut to "uninstall" same like above steps and Paste that shortcut under user's programs menu like this
image16


Select that uninstall short cut right click choose Properties.
image17


In that property window give Arguments value /u=[ProductCode]
.
image18


Now select set up file in solution explorer and build it
image19


In this example I have create project "D:\WindowsSetup" name. So now I go to my project location "D:\WindowsSetup" Set up file folder "Windows_Setup" is available in that project folder and set up file is available in this path "D:\WindowsSetup\Windows_Setup\Debug" folder.
image20


Just I double click that set up file to install in my system. After installation Shortcut for that application is created automatically in Desktop and Program files menu.


Desktop shortcut
image21


Program Menu Shortcut with uninstall option
image22


Source Code
Here i have attached source code, if you want source then download it and try to create set up file.

Conclusion:
I hope this article help to know about set up file creation using Visual Studio for .Net application.


Attachments

  • Source_code (43059-231231-WindowsSetup.rar)
  • Comments

    Author: Jitendra Chandrakant More14 Jul 2011 Member Level: Silver   Points : 0

    I like it very much and will help me in creating the setup of my project.Thank you very much.

    Author: BHANU PRAKASH BYSANI20 Jul 2011 Member Level: Gold   Points : 1

    hi After building the project iam getting this error


    Error 1 Unrecoverable build error F:\WindowsFormsApplication1\Setup1\Setup1.vdproj Setup1

    and in debug folder a file is creating tmp file..

    plz help me in rectifying the error

    Author: Ravindran20 Jul 2011 Member Level: Diamond   Points : 1

    @BHANU

    Reason for your error may be version compatible problem or some Mergemod.dll not register please check this link

    http://support.microsoft.com/kb/329214/EN-US/

    Author: SonyShiva27 Aug 2011 Member Level: Gold   Points : 1

    Hi Ravindran,


    This article is nice.
    Just i downloaded and followed your steps.I double click that set up file to install in my system. After installation,
    1.Icon with text 'h'
    2.Windowssetup
    3.WindowsSetUp.exe XmlConfiguration file
    4.Icon with 'DskShortcut'
    the above 1 to 3 are also created in Desktop.




    Regards,
    Madhu




    Author: Harsha27 Aug 2011 Member Level: Bronze   Points : 0

    It's help me so much in my project.. thank you

    Author: AMISH KUMAR22 Nov 2011 Member Level: Bronze   Points : 0

    its a very fantastic site to learn thanks alot

    Author: Sagar S pawar07 Dec 2011 Member Level: Gold   Points : 0

    its a very nice resource.
    I learn to add uninstall method in installer.

    Author: manikandan13 Mar 2012 Member Level: Bronze   Points : 0

    i got litral ans...thanks

    Guest Author: Uknees19 Mar 2012

    Hi Jim, thanks for neltitg me know about this. The WordPress module seems to work fine with Safari, but the Joomla module doesn't. I'm going to look into it and will be back as soon as possible with the solution.

    Guest Author: balu20 Aug 2012

    i go through the above process .. but i got error.. that i am receiving data from database ok.. when i am inserting data into emp table(in the application window after installation) it show error ..'operation must use an updatable quer'.. when i open .accdb (database) file in installation folder(c:\...) it shows that it is read only ...

    Author: Dinesh Kudale22 Aug 2012 Member Level: Silver   Points : 1

    First time, I am creating setup file after seen your screen shot.
    Really it is very useful to fresher / student like me who want to know that how to create set up file of own program.
    Again,really,really,really thanks.

    Author: Ravindran22 Aug 2012 Member Level: Diamond   Points : 0

    Balu make sure it is permission issue mostly it comes it windows7 OS. Make sure you have set sufficient permission to access that folder and database

    Author: Ravindran22 Aug 2012 Member Level: Diamond   Points : 0

    Thanks Dinesh

    Author: siraj30 Aug 2012 Member Level: Bronze   Points : 0

    superbb

    Guest Author: Akumar09 Oct 2012

    After deployment i installed my windows application in the user's system.how can i see the data's in the user's system

    Guest Author: Archal Gharat18 Oct 2012

    Thanks a lot! I have successfully created the setup file. But the uninstall in Program menu again opens my application instead of uninstalling the application from my system. Can u help me??

    Author: Ravindran29 Oct 2012 Member Level: Diamond   Points : 3

    Archal make sure your write this code in form load


    private void Form1_Load(object sender, EventArgs e)
    {
    //Below code is used to uninstall application

    //Get Command Line Arguments
    string[] arguments = Environment.GetCommandLineArgs();
    foreach (string argument in arguments)
    {
    if (argument.Split('=')[0].ToLower() == "/u")
    {
    string guid = argument.Split('=')[1];
    string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
    ProcessStartInfo si = new ProcessStartInfo(path + "\\msiexec.exe", "/i " + guid);
    Process.Start(si);
    Close();
    Application.Exit();
    System.Environment.Exit(0);
    }
    }

    //Load DataGridView first time when form load
    refreshGrid();
    }

    Guest Author: Abhishek19 Dec 2012

    Nice Sir but how i make .exe using Registration key with our own.

    Guest Author: Meena Rawat14 Feb 2013

    hey
    when i install setup then it is not working ...
    don't know what would be happen..
    please suggest me what i have to do ... plzzz

    Author: Murugesan.P21 Feb 2013 Member Level: Silver   Points : 0

    it is very use ful.....but I m using SQL SERVER

    I want the same Steps for SQL SERVER 2008(.mdf file)


    Thank u,
    MURUGESAN.P

    Guest Author: smitha23 Mar 2013

    Very well explained..This is exactly what i wanted..thankx for saving my time..

    Guest Author: Vinod06 May 2013

    Hi,Thanks
    it's very useful for me fist time but, i want to install this setup on other system so, pl suggest me what i have to do?

    Guest Author: Barmala Sharma22 Jan 2014

    This program is nice but i want create a setup for in build sql data base so that i could install another system where will not be required for sql server software. please help me

    Author: Ultimaterengan07 Feb 2014 Member Level: Gold   Points : 6

    Try this article also

    Create Setup Project:-
    Step1:
    File->New->Project->Choose Setup and deloyment from other Project Types in Project Types.
    Then go to templates click Setup wizard.Then give new name to Setup Wizard and choose your path.For Example Setup1
    Then click Ok.(See Image:1)
    Step2:-
    Welcome to the Setup wizard(1-4) window will dispaly(See Image:2).Then click Next.
    Step3:-
    Setup wizard(2-4) window will dispaly.(See Image:3)
    Do you want to create a setup program to insatll an application? message will appear.
    Default is "Create a setup for a windows application".
    No need to change anything.Just click next button.
    Step 4:-
    Setup wizard(3-4) window will dispaly.(See Image:4)
    Choose Files to include message will appear with in window.
    Which additional files do you want to include?
    Click the add button.After click the add button "Add Files" window will appear(See Image:6) then go the project location(For Ex:-Windows application1)
    Click The project(Windows application1)->click Windows application1->choose bin folder->Debug->Finally choose "WindowsApplication1.vshost.exe"
    Then click the open button.
    You will get the your exe path with in Setup wizard(3-4) window.Then Click The Next Button.

    Step 5:-
    Setup wizard(4-4) window will dispaly.(See Image:5)
    The project summary will display based on your choose.
    Project type: Create a setup for a Windows application
    Project groups to include: (none)
    Additional files:
    C:\Documents and Settings\ramku.g\Desktop\WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe
    Project Directory: C:\Documents and Settings\ramku.g\Desktop\Setup1\Setup1\Setup1.vdproj
    Project Directory: Your path will display
    Then click finish button.

    Step 6:-
    File System(Setup) window will dispaly.(See Image:7)
    Then go to the solution explorer window(See Image:8) and Right click the project name then build the windows application.
    Build Success message will dispaly on status bar.After that right click the project name then click install.
    Step 7:-
    Welcome to the setup wizard window will dispaly(See Image:9).Then click next Button
    "Choose the installation folder" window will dispaly(See Image:10).Selet the Insatllation folder path by clicking browse button.
    choose justme or Every one from radiobutton.
    Then click next button.
    Step 8:-
    Confirm installation window will dispaly(See Image:11).
    If you want to install ,just click Next.
    Setup will install(See Image:12).
    Step 9:-
    After install installaion complete window will display(See Image:13).
    Then close.Just go that path and choose that exe and run it.


    http://www.dotnetspider.com/resources/39105-How-create-Setup-for-windows-application.aspx

    Guest Author: tharif15 Jul 2014

    This is Excellent working in Access database(.mdb)..in other machines also..other machines needed .Net Framework & visual c++ Redistributable package.(As per your Visual Studio Deployment)..thanks saved my time...but SQL database..in other machines does not work.while error in Sql Connection...pls any one can help me..pls pls pls help..pls
    pls

    Author: Mohammed Tharif.A15 Jul 2014 Member Level: Bronze   Points : 3

    this is excellent working for MS-Access Data base(.mdb) client machines also..In client machines needed .Net Framework & Visual c++ Redistributable Packages..thanks saved my time...

    but it does not working with MS-SQL Data Base(.sql) on client machines..error-while connecting to the SQL Server..(what is need for client machines) please anyone help me..pls pls pls help..me



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: