Click here to Skip to main content
15,867,488 members
Articles / Operating Systems / Windows
Article

Visual Studio Windows Application Setup Project

Rate me:
Please Sign up or sign in to vote.
4.73/5 (88 votes)
29 Dec 2005CPOL5 min read 1.7M   9.6K   167   378
This article shows how to create and use the Windows Application Setup Project.

Image 1

Introduction

I noticed that there are several articles on using Web Setup projects, but no articles could be found for Windows Setup projects. So I decided to share what I know about the VS Windows Setup Projects. I will be using the RunOnlyOnceCS.exe demo app I created for another CodeProject article, as the application we are creating the setup for.

Background

Sooner or later, you need to create a setup project for an application. Personally, I am not a big fan of this type of distribution for an application. Still it has its uses. Using a setup project can be a good solution for a Windows application that has many dependencies on other assemblies / DLLs. The setup will figure out what the dependencies are for the application and automatically include them.

Note: This does not include the .NET framework.

Creating a Setup Project

This article is going to rely on screen prints since there really isn’t any code for this. The output will be a *.msi file that will install the application file(s), and add a shortcut to the desktop and to the Programs menu.

Note: if the user does not have admin rights to their box, they will not be able to run the MSI script or install new applications on their box.

Image 2

After you have created a new setup project, the first thing you will want to do is change the ProductName property on the setup project to match the application you are creating the setup for. I would also suggest changing the RemovePreviousVersion property to true. This is helpful when you want to release your next version of your app through this setup project.

Image 3

Next, click on the "Application folder", then right click, and click on Add/File. At this point, you will be able to add the Exe you are trying to create the setup for.

Note: if you make changes to the Exe, you will need to re-compile the setup project as well. It might be a good choice to add a setup project to your Windows project solution. Then you can choose the project output option instead of the file.

Note: if you know what a merge module is and want to add one to the setup project, you need to right click on the setup project and click Add Merge Module.

Note: you must also add any config or icon files you may need for this solution, here:

Image 4

Next, I always set the Always Create for the Program Directory to true. This is done by clicking on the "Application Folder" and then going to the properties.

Note: the DefaultLocation property will always be: [ProgramFilesFolder] [Manufacturer]\[ProductName]. If you want it to be something else, this is where to change it. Notice that the solution explorer has recognized the dependency or need for the .NET Framework for this app to run.

Note: this does not mean that the setup will install the .NET re-distributable framework. That is its own setup. The setup file is around 24 MB in size and can be downloaded from here.

Note: the setup can not install a .NET application without the .NET Framework already installed.

Image 5

Next, we want to create a shortcut to our application on the desktop. First, click on the "User's desktop" folder. Then right click and click on "Create New Shortcut".

Image 6

Next, you will see a dialog box to choose the application you want to create a shortcut to. Go to "Application folder" and add the exe you added in the previous step.

Image 7

If you click on the "User's desktop" and go to the Properties window, you will see some options. Something I normally add to the shortcut is a check to see if it already exists. This is an example of what little coding you can do in a setup project. I have turned on AlwaysCreate on the shortcut property. In doing this, I need to have a condition or I will multiply my desktop shortcuts with every new release. So I set the Transitive property to True and I set the condition to FILEEXISTS1<>"Shortcut to RunOnceOnlyCS.exe", where what is in the "" needs to match the name of the shortcut.

Image 8

Note: if you want your shortcut to have your application's icon, you need to add your icon file to the "Application folder". Next, click on the shortcut you just created in your "User's desktop". There is an icon property. Click the down arrow to get the dialog box. Navigate to the "Application folder" and select the icon file you just added.

Next, if you want to create a shortcut in the Start/All Programs menu, it is very similar to creating a shortcut on the "User's desktop". First, click on the "User's programs menu", then right click and add a folder. Name the folder the same as whatever your company or manufacturer name would be. Then, click on that newly created folder and add a shortcut just like we did in the step above.

Image 9

Finally, when you need to create a new setup for the next release of your application, you need to go to the setup project properties and change the version before you re-compile the setup project.

Image 10

Once you click off the version property, you will get a prompt to update the GUID for the ProductCode.

Note: if you do not click the Yes button in the dialog, you must manually get a new GUID for the ProductCode for the setup to properly remove the old program and install the new program.

Image 11

Note Do Not: change the UpgradeCode GUID. If you do, the user will have to uninstall the old program manually before the new version can be installed.

One last note

One thing that is really nice about the Setup Project is that it automatically adds your Windows application you are trying to install to Add/Remove Programs. So once this has been installed, you can go to Add/Remove Programs and remove the app, and it will clean up all the files and folders that were created. I guess this is in part why you might be using a setup project in the first place.

Conclusion

I hope this article has given you a taste of how to use the VS Setup Project. It is not the perfect solution for distributing Windows applications, but it is useful in certain situations where this solution fits the need.

License

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


Written By
Software Developer (Senior)
United States United States
I started my programmer career over 26 years ago doing COBOL and SAS on a MVS mainframe. It didn't take long for me to move into windows programming. I started my windows programming in Delphi (Pascal) with a Microsoft SQL server back end. I started working with vb.net when the beta 2 came out in 2001. After spending most of my programming life as a windows programmer I started to check out asp.net in 2004. I achieved my MCSD.net in April 2005. I have done a lot of MS SQL database stuff. I have a lot of experience with Window Service and Web services as well. I spent three years as a consultant programing in C#. I really enjoyed it and found the switch between vb.net and C# to be mostly syntax. In my current position I am programming in C# working on WPF and MSSql database stuff. Lately I have been using VS2019.

On a personal note I am a born again Christian, if anyone has any questions about what it means to have a right relationship with God or if you have questions about who Jesus Christ is, send me an e-mail. ben.kubicek[at]netzero[dot]com You need to replace the [at] with @ and [dot] with . for the email to work. My relationship with God gives purpose and meaning to my life.

Comments and Discussions

 
QuestionHow to add EULA and README Pin
Jay Kay16-Jun-09 15:05
Jay Kay16-Jun-09 15:05 
AnswerRe: How to add EULA and README Pin
Jay Kay16-Jun-09 15:12
Jay Kay16-Jun-09 15:12 
GeneralInstall .net framework during setup installation Pin
patibandha sapan3-Jun-09 20:48
patibandha sapan3-Jun-09 20:48 
GeneralRe: Install .net framework during setup installation Pin
kubben4-Jun-09 0:47
kubben4-Jun-09 0:47 
GeneralRe: Install .net framework during setup installation Pin
patibandha sapan4-Jun-09 1:16
patibandha sapan4-Jun-09 1:16 
GeneralRe: Install .net framework during setup installation Pin
kubben4-Jun-09 1:20
kubben4-Jun-09 1:20 
GeneralRe: Install .net framework during setup installation Pin
Danielku157-Sep-09 17:04
Danielku157-Sep-09 17:04 
GeneralRe: Install .net framework during setup installation Pin
kubben8-Sep-09 1:30
kubben8-Sep-09 1:30 
QuestionReferencing the Setup Project in Windows Project Solution Pin
vlakes3-Jun-09 8:43
vlakes3-Jun-09 8:43 
AnswerRe: Referencing the Setup Project in Windows Project Solution Pin
kubben3-Jun-09 8:58
kubben3-Jun-09 8:58 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
vlakes3-Jun-09 9:08
vlakes3-Jun-09 9:08 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
vlakes3-Jun-09 10:12
vlakes3-Jun-09 10:12 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
kubben3-Jun-09 14:07
kubben3-Jun-09 14:07 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
vlakes4-Jun-09 2:02
vlakes4-Jun-09 2:02 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
kubben4-Jun-09 2:05
kubben4-Jun-09 2:05 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
vlakes4-Jun-09 2:26
vlakes4-Jun-09 2:26 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
kubben4-Jun-09 2:33
kubben4-Jun-09 2:33 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
vlakes4-Jun-09 2:20
vlakes4-Jun-09 2:20 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
kubben4-Jun-09 2:25
kubben4-Jun-09 2:25 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
vlakes4-Jun-09 2:36
vlakes4-Jun-09 2:36 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
kubben4-Jun-09 3:11
kubben4-Jun-09 3:11 
GeneralRe: Referencing the Setup Project in Windows Project Solution [modified] Pin
vlakes4-Jun-09 3:19
vlakes4-Jun-09 3:19 
GeneralRe: Referencing the Setup Project in Windows Project Solution Pin
vlakes4-Jun-09 2:58
vlakes4-Jun-09 2:58 
QuestionStart application when click Finish button. Pin
eight26-Apr-09 18:11
eight26-Apr-09 18:11 
AnswerRe: Start application when click Finish button. Pin
kubben27-Apr-09 0:52
kubben27-Apr-09 0:52 

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.