Page 1 of 1

Creating an Installer And I said, "Let Visual Studio work everywhere!" Rate Topic: -----

#1 Psionics   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 158
  • Joined: 06-September 08

Posted 24 January 2009 - 11:39 PM

You remember that kick ass piece software you wrote? And remember when you went to Microsoft and tried to sell it, but when you ran your .exe it just crashed? And you're all standing there is this?! Dll's my good sir, dll's. Now since this is not a tutorial on dynamic linked libraries, I'm not going to go into what they are, but feel free to type Dlls (just like that) into the MSDN, and read for a few days *cough* months all you'd like :)

But just so we have an understanding, when you installed VS on your PC, VS installed lots of goodies on your machine - many of which allow your programs to execute after it's compiled. Keep in mind that Visual Studio is not the compiler, nor the linker - it's simply an IDE. When you build your solution, a separate EXE (located around here: C:\Program Files\Microsoft Visual Studio 9.0\VC\bin) which is called 'cl' - and this is what compiles your code, followed promptly by the 'link.exe', also in the same folder. Just an FYI.

Anywho and unfortunately, taking your compiled .exe to a computer without this installed doesn't have those lovely dll's to use. Thus, we write an installer that will allow this to happen. Plus, it looks a lot more professional than just handing someone a .exe and saying, "here....have fun!". I don't know about you but there's only so many people in this WORLD that I'll just run some random .exe off of ;)

Without any further ado, let's begin!

This tut will cover, from start to finish, how to create a fully working installer. I've also included many Tips & Tricks to do other, advanced/cool things with the installer, but if the bare bones is all you want, feel free to skip those sections. This will work for both Console and Windows APIs. Just note that below, we'll talk about adding content to the installer, and if you're in Console, you probably won't have any in there.

The windows you'll need for this are the Solution Explorer, and Properties for many of the tips. You'll be adding a new project to whatever solution you want to make this for.

// Step 1: The only step - setup wizards ftw!

1 - Right click on the solution in the Solution Explorer, and click Add new project.
2 - In the project types section, open the tab labeled Other Project Types.
3 - the the Setup and Development, select the Setup Wizard and call it whatever you'd like.
4 - You'll want to select the option for whatever you're doing, but if you're making a windows app, you'll obviously select the Create setup for Win app.
5 - On the next window, you can pick and choose whatever you want, but the two items you'll definitely want are the 'Primary Output from MyProgram' and 'Content Files from MyProgram' -- where MyProgram will be the name of your solution.
6 - Next you'll be prompted to choose files to include. This would be where you're include any fonts, bmps, sound files, gifs, and all the like that your project uses. If you forget to do it here, don't worry! There's actually 3 different ways to accomplish this, which we'll touch later.
7 - Finally, you'll see a summary, then click Finish.

Now technically, right now you're all done (assuming you have all the files your program needs). One thing to note is by building your project (Ctrl+Shift+'B'), this won't build the installer you just made. Instead, right click on that project in your Solution Explorer, and build it that way (take note of what it's building). You'll find in the folder of this solution, the a folder with the name of the installer you just created.

Inside this folder, you'll see a Debug, Release, and Visual Studio Deployment Project file. Whatever mode you built in, select that folder, and you'll find two installer files. The one labeled with whatever you called Setup is for machines that already have VS on it. The one that is labeled Installer (or whatever you called it) is the one you'll have your users run. Remember this, because you won't be able to tell the difference on your machine ;)

JUST NOTE THAT IT IS WISE TO GIVE THE USER THE VS INSTALLER FILE AND BOTH SETUP FILES. Although I've never tried giving someone only one, or only two, I've heard horror stories.....terrible terrible things...but not as bad as calling main inside itself (go ahead, try it).

// Now, for a few tips and tricks with this little guy

After you've created this guy, VS will open up a split screen view in the client area. On the left, the File System on Target Machine, with three folders underneath. The top folder (Application Folder) resides all the content that your program needs to run (the ones you included during the wizard). Underneath (User's Desktop) is where you can tell the installer to create a desktop icon (shown below). Finally (User's Programs Menu) is where you'd tell whether or not to make an entry in the start menu.

// Strings used in the installer

So first things first, naming spots. If you select the project in your Solution explorer, you'll notice a bunch of stuff in the properties window, and here's some info on them (aside from what VS tells you):
Author - this will appear in the info section when the user launches the installer.
Manufacturer - this will be the name of the folder it installs to in the program files on the user's drive.
ProductName - this will appear in the title bar of the installer while running, as well as many many other places.

// Organize the created folder on the user's machine

By selecting 'Application Folder' in the client area, on the right hand side you'll see all the files you included in this project. Now by default, this will all be in one folder, including the EXE. Now obviously if you have a ton of stuff in there, this could get out of hand quickly. Remedy this by right clicking in the right hand side, and add new folder. Drag the content 'Content Files from MyProgram' and whatever files you want in that folder. You can make as many folders as you wish.

NOTE: Please be advised that by right clicking on the 'Application Folder' in the left pane, and adding a folder there will not have the effects you desire. For whatever reason, that doesn't create a folder on the user's system (or when I first learned this I did it wrong, and never went back to check it out..hmm...should do that).

NOTE: Please also take notice of how you were calling those files in your program, as they'll have to match. A simple way to check this is underneath where you loaded in the bmp or whatever file, check to make sure that what you created it in isn't null (which you should be doing anyway). Easiest way - just do like a blank MessageBox(0,0,0,0) or print out whatever error you want. Then try and install it on your computer, run that EXE, and make sure none of those little guys pop up.

// Create a shortcut on their desktop

Back on the client area, select the 'User's Desktop' option, then right click on the right pane, and select 'Create new shortcut'. Here, I'm 100% sure that you must do it like this. A child window will pop up, and you'll select 'Application Folder' and click OK. On the next selection screen, select 'Primary Output from MyProgram (Active) and click OK. That 'Primary Output...' is you're .exe. Name it whatever you want, and there's just one last, VERY important step.

Back in the client area, select the 'User's Desktop'. In the properties window, you'll see AlwaysCreate, and it will, by default, be set to FALSE. Change this to true, for it not, it won't create the shortcut.

Please note that by right clicking on the left pane's 'user's desktop' and trying to create the shortcut that way WILL NOT WORK. Why it does what it does is beyond me, but if you're curious enough, give it a try! Silly bill... (oh my compiler's name is bill by the by).

I hope you enjoyed this! Happy Coding :)

This post has been edited by Psionics: 27 January 2009 - 12:38 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Creating an Installer

#2 Axman10   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 17-November 11

Posted 17 November 2011 - 05:16 PM

Cool post, but this doesn't seem to work with VC++ 2010. Any chance of an update for it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1