So you may or may not be aware that Visual Studio 2012 no longer has a built in project that will install your application for you – I can understand why this is, as it allows third parties to develop these and lets them focus on improving the programming experience, but I can also understand that this change has frustrated and confused developers (like myself). So I thought I’d share a guide as to how you can create an installer for your Visual Studio 2012 project (NOTE this also works in older versions).
First of all download and install the WiX toolset (you can do this by either going to http://wixtoolset.org/ or by going through Tools -> Extensions and Updates from within Visual Studio). WiX stands for Windows Installer XML and basically allows you to write XML files that define what you want to install; you can compile the project and it builds you an MSI that can then be used to install your application – easy!
Next, open up Visual Studio (if it isn’t already) and right click your solution then pick Add -> New Project… and you will see the Add New Project Dialog box. Go to Templates -> Windows Installer XML and then pick Setup Project and give it a name. This project will sit in your solution alongside your existing project – it will use the output from your project as input for the MSI that it will compile.
You will see that it has added the project to your solution and opened a Product.wxs file with some basic configuration settings. Now you just need to customise these settings:
- On line 3 change the Name to the name of your product and the manufacturer to the name of your organisation
- On line 17 change the Name to the name of the folder you want to install to (the default location is the Program Files folder)
- Replaces lines 24-27 with the follow:
<Component Id="FILENAME" Guid="GUID"> <File Id="FILENAME" Name="FILENAME" Source="..\PROJECTNAME\bin\Debug\FILENAME" Vital="yes" KeyPath="yes" DiskId="1"/> </Component>
where GUID is a unique Guid*, FILENAME is the name of your executable and PROJECTNAME is the name of your main project
- Repeat step 3 for every required file and then compile your install project. You will find the compiled MSI in the bin folder of the install project
For further information on this please read the manual.
Services
Most application developers can stop here, however, if your project is a service then you will want to read on. You should have already built a Service and ServiceInstaller, if not then I suggest you read Creating a Simple Windows Service in C#. To install the service once you have copied over your files (step 3/4) add the following code to your ComponentGroup (somewhere after line 23, preferably after your other components as they may be required):
<Component Id="FILENAME" Guid="GUID"> <File Id="FILENAME" Name="FILENAME" Source="..\PROJECTNAME\bin\Debug\FILENAME" Vital="yes" KeyPath="yes" DiskId="1" Checksum="yes"/> <ServiceInstall Id="SERVICEINSTALLERNAME" Type="ownProcess" Vital="yes" Name="PROJECTNAME" DisplayName="PROJECTNAME" Description="DESCRIPTION" Start="auto" Account="LocalSystem" ErrorControl="ignore" Interactive="no"> </ServiceInstall> <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="PROJECTNAME" Wait="yes" /> </Component>
where again GUID is a unique Guid*, FILENAME is the name of your executable, PROJECTNAME is the name of your main project, SERVICEINSTALLER is the name of your ServiceInstaller (this is key) and DESCRIPTION is the name of your service.
*To generate a new Guid go to Tools -> Create GUID, select option 4 (Registry Format) and then click Copy.