I have an application with complex setup requirements. I'm well familiar with some of the tools out there for creating setup programs such as Wix, Visual Studio Setup project, Inno-setup and 3rd party tools. For this particular app however, I've determined that I need to write the setup program from scratch in C#, not using any of those tools. Some of the reasoning expressed by Joel applies here, except I want to do this in C# instead of MFC.
Anyway, my question is: how would I go about creating a .NET executable that can contain a set of files which are extracted at run time? In this case the exe is the setup program and the files are the program files that it needs to install. Also, how do I make the program executable completely standalone, i.e. even though I am using some external assemblies (my own as well as 3rd party) I want them to be packed together into a single EXE (in C/C++ native world this was accomplished via static linking).
UPDATE
This is the approach I have gotten working so far, which I will stick with unless someone suggests something better:
- Created a manifest file in XML containing the list of all the files and the folder structure comprising the application that my setup program is installing. I added this file to the VS project for the setup program.
- Wrote a tool in C# (zipfiles.exe) which takes the manifest XML and creates a zip file containing all the files. This tool uses the awesome DotNetZip library to create the zip.
- Added a Pre-Build action to my setup program project that launches the zipfiles tool with the manifest XML and outputs the zip file (Files.zip) in the project folder.
- Added Files.zip as an embedded resource in my setup program project.
- My setup program at runtime extracts the embedded zip and unzips it to the target install folder for the application (again using DotNetZip)
- Added a Post-Build action to my setup program project which uses the ILMerge tool to bundle all the external assemblies that it uses into the exe.
I now have a VS project for my setup program which builds a self-contained exe with all the files it needs to install embedded in it. When the list of files for the application being installed changes, I simply update the manifest XML and rebuild.
Now I can focus on the rest of my setup logic!