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.
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.
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.
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:
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.
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.
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".
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.
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.
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.
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.
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.
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.
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.