In this article I will go through setting up a .NET installer project step-by-step for when you want to automate installation of a .NET Windows Forms Application. I’m assuming here that you have already put together your actual application and that you want to set up an installer for it now.
These steps are specific for Visual Studio 2010. If you are using an earlier or later version of Visual Studio, then the location of the menu options may vary slightly.
If you found this article interesting, please have a look at some of my other .NET articles.
Thoughts on Which Installer Project to Choose
Visual Studio 2010 supports two options for installer projects. These are:
- A Setup Project Installer
- A Setup Wizard Installer
The step-by-step example in this article covers creating a basic custom installer (Setup Project). However the options are similar for an installer project created using the installer Wizard setup (Setup Wizard), after the Wizard has finished generating the project for you.
Starting your installer by using the custom installer gives you more granular control over how your installer functions and the setup requires about as much effort as the Wizard. Because it is so easy to put together a custom installer and because it gives you much more granular control over what happens during the installation, I really suggest setting up your installer yourself instead of using the Setup Wizard. It’s really just a matter of personal preference though.
Steps to Set up Your Installer Project
- Right-click on your solution in solution explorer
- Then select Add –> New Project
- Expand Other Project Types
- Expand Setup and Deployment
- Select Visual Studio Installer
- Select Setup Project and give it an appropriate name in the name field at the bottom of the wizard.
- *Note: give your setup project a name that you would like it to appear as on the end-user’s computer. Don’t name it something like SetupAbc… instead use a descriptive name like your project’s name.
- Click OK
- * The new project should now appear below your Windows Application project
You can check that your project is properly added by:
- Clicking Project in the top menu bar
- Selecting Project Dependencies
- In the popup that appears, make sure the projects you want included are checked. You can also set the build order for your projects in the Build Order tab.
- Select OK to save the dependencies.
Adding your Windows Form Assemblies to your Setup Project
- Click Application Folder in the Setup Project
- Right-click in the main window and select Add –> Project Output
- Make sure Primary Output is selected. This will include the DLL or EXE from your main project.
- Click OK
- Ensure that in the Solution Explorer of the Install Project that you see a folder called Detected Dependencies and that it contains the Microsoft .NET Framework.
Choose to add your new application to the end-user’s Desktop and/or Programs Menu
- Click User’s Desktop under File System on Target Machine.
- In the main content pane right click and select: Create New ShortCut
- Select Application Folder (which you set up in a previous step to hold your application’s assemblies)
- Click OK
- Select the Primary output from [your Windows Form Project Name]
- Click OK
- Give your new ShortCut a descriptive name that your end-users will recognize as your application.
When you are ready to test your installer project:
- Right Click on your Installer Project in the Solution Explorer Window
- Select Build
- The Compiler Output pane at the bottom of Visual Studio will show you if the build was successful, and the directory in which to find the .msi installer file.
Testing a Mock Installation of Your New Application:
- Browse to the output directory of your installer project (you can find this in the Compiler Output pane at the bottom of Visual Studio after a successful build)
- Make sure you have both a .msi and a Setup.exe file
- Copy both files to a folder on your hard-drive
- Test the installation by double-clicking the Setup.exe file.
- Go through the installation wizard for your application. At the end of the installation make sure that your Windows Application is now properly installed on your system.