How to Create a Setup of Windows Application in .NET

This article shows how to create a setup of a Windows application.

To create the setup I will use the following 2 steps:

  1. Create a Windows Forms application
  2. Create a setup and deployment project.

Step 1

a. Create a Windows Forms application named "WindowsFormsApplication1".


b. Place a button on "Form1 " design.

 

c. Double-click on the button; that will generate a Click event for the button in the form. Then use the following code to show a Message Box when the button is clicked.

private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show("This is windows Setup Project");
}
 


d. Run the application, which shows the form like this:
 


And when you click on the button it will show the message.
 


Step 2

a. Right-click on the solution and choose "Add" -> "New Project" to add a new setup project.
 
 

b. Create a "Select project" named "Setup1" from the "Other Project Types -> Visual Studio installer".

 

c. Now in the file system you will get 3 items that will create an application file for 3 locations respectively.
  1. Application Folder: In the application folder like "Program Files".
  2. User's Desktop: On the desktop of the user.
  3. User's Program Menu: In the program menu of the user's system.

1. Application Folder

Right-click on Application Folder to add the project output.



Select the primary output as in the following:
 


Change the property "Always create" to True in the property window by right-clicking on the Application Folder.
 


2. User's Desktop

Right-click on User's Desktop to add the project output.



Select the primary output.
 


Change the property "Always create" to True in the property window by right-clicking on the User's Desktop.
 


3. User's Program Menu

Right-click on the User's Program Menu to add the project output.



Select the primary output.
 


Change the property "Always create" to True in the property window by right-clicking on the User's Program Menu.
 


Note: You can see in the following image that the .Net Framework has been automatically added to the project because if any user doesn't have the .Net Framework then this setup will install the .Net Framework first.
 


Get the setup file from the debug drectory of the path of your setup project.
 


Now time to install the setup on the user's machine/system. Right now I am installing it on my own system.
 


It runs successfully.
 


You can check that it generated the file in the "Program Files" folder due to the Application Folder.
 


You can check if it generates the file in the "Programs Menu folder due to the User's Desktop.
 


You can check if it generates the file in the "Programs Menu" folder due to the user's Program Menu.
 


You can also check the "Programs and features" from the Control Panel. 
 
 


Similar Articles