Google Analytics

Tuesday, February 5, 2013

Beginning Wix 3.7 with VisualStudio 2012


Background

Our development team has been working on projects with basically a .Net flavored stack. We are creating WPF clients for services using WCF with SQL 2008 on the backend. Instead of Team Foundation Server there was an organizational decision to use the Atlassian suite of project management tools: Jira with Greenhopper, Bamboo, and Fisheye. Currently we are still using Subversion but there is some movement towards using Atlassian's Stash with Git.

We were primarily using Visual Studio Installer Setup Projects to create our installers. It was relatively simple when be started, but became more involved as we created custom actions and extended the installers. With Microsoft dropping support of the Setup projects (http://blogs.msdn.com/b/buckh/archive/2011/03/17/visual-studio-setup-projects-vdproj-will-not-ship-with-future-versions-of-vs.aspx) and a rather abrupt shift to using Visual Studio 2012 we needed to implement a Wix solution for our installers in rapid order.

The Wix tutorial (http://wix.tramontana.co.hu/tutorial) is fantastic and really quite thorough, but it only deals with building from an IDE like VisualStudio in general terms. So, I thought I'd compile what I did for walking through the tutorial using Wix 3.7 and Visual Studio 2012.

Getting Started

I'll assume you have Visual Studio 2012 and the Wix toolset (http://wixtoolset.org/ v3.7: http://wix.codeplex.com/releases/view/99514). Also you should review the tutorial. My walk-through is in no way meant to be as comprehensive as that tutorial, but rather to get one started using Wix with Visual Studio 2012. The tutorial also does a good job explaining 'candle' and 'light' and the other associated tools in the Wix toolkit. Finally, at least initially I will use the sample files from the tutorial: a simple executable, dll library, and user manual (http://wix.tramontana.co.hu/system/files/samples/SampleFirst.zip).
- The Software Package

I start by selecting File > New > Project in VS. If you have the Wix toolset installed you should see a Wix Setup Project template under Templates > Visual C# > Windows Installer XML.



I created my project with the name “WixTutorial”.
Wix has now created a Setup Project and an initial Product.wxs file.
The Product element has a wildcard “*” in the Id field. The wildcard will be turned into a random GUID at compile time. This isn’t necessarily a big deal since the recommended approach is to always to a major upgrade as opposed to minor upgrades or patches, but until I understand the upgrade process a bit better I’m replacing the wildcard with a generated GUID. By default the Id field in other elements that haveuse GUIDs as ID are defaulted to the wildcard. From what I’ve seen so far this is actually preferred even for components providing you are using the single file per component approach (http://stackoverflow.com/questions/1602831/wix-one-file-per-component-or-several-files-per-component/1604348#1604348).

While Wix adds the Language attribute to the Product (defaulted to ‘1033’ - English) it does not add the Codepage attribute, which is the character set used. I don’t know if this is simply defaulted to ‘1252’ now or is based on the Language attribute. As multi-language support is beyond the scope of this now, I’m just leaving it.

To the Package element I also add the Keywords, Description, Comments, and Manufacturer attributes as these are shown in the properties of the MSI package in Windows. The InstallerVersion is the minimum version of WindowsInstaller to be used. Wix has set this to 200 (WindowsInstaller v2.0) and I will leave this until it warrants some change. Compressed=”yes” indicates to use compressed (.cab) installer files. The InstallScope attribute is new since the tutorial. InstallScope=”perMachine” sets the installation scope for “All Users”. This can also be set to “perUser”. The “perMachine” installation will require elevated permissions to install the software.

The MajorUpgrade element tells MSI how to handle product upgrades. For now the default that Wix has in is sufficient.  I’ve added the EmbedCab=”yes” attribute to the empty MediaTemplate element that Wix created. This way my .cab files will be packaged in the .msi file. I’m not using the separate Media elements as the tutorial describes as I don’t plan to put the installer on separate media. The tutorial explains how to use this, however.

Finally Wix has added a feature element with a child ComponentGroupRef element. This differs from the tutorial, which has us create the entire directory hierarchy with the components within it. Instead Wix has created the directory structure and components within separate fragments. The tutorial explains this approach in Upgrades and Modularization > Fragments (http://wix.tramontana.co.hu/tutorial/upgrades-and-modularization/fragments), and I think it is a cleaner approach and easier to refactor common elements later. I changed the default Id and Title to fall in line with the tutorial. The Level is used to determine if the feature should be installed in a “Typical”, “Custom” or “Complete” installation. For our main feature it should be left at 1.

I also added a second ComponentGroupRef element that will refer to my shortcut files as those get installed to a different directory than our main install directory.

<Product Id="E240A99B-A6A2-41A6-A8F9-DF388EBAD98B" Name="Fubar 1.0" Language="1033"
    Version="1.0.0.0" Manufacturer="Dominion Voting Systems" UpgradeCode="585749c0-d21d-453f-bcbf-a565bbf0431d">
    <Package Keywords="Installer" Description="FUBAR Test Wix Installer"
        Comments="This is a test installer package." Manufacturer="Dominion Voting Systems" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <Feature Id="Complete" Title="Fubar 1.0 Complete" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
        <ComponentGroupRef Id="Shortcuts" />
    </Feature>
</Product>

The Files Inside

As described in the tutorial we lay out a hierarchical directory structure that Windows Installer will recreate upon installation. It then installs the components into the directories to which they are assigned. The top level directory has a predefined name “TARGETDIR”. The next level also uses a predefined name “ProgramFilesFolder” to indicate to MSI to install to the Windows Program Files directory. (A complete list of predefined names is here: http://kb.flexerasoftware.com/selfservice/viewContent.do?externalID=Q105880) . Finally we have an “INSTALLFOLDER” directory. This is not a predefined directory. INSTALLFOLDER is the ID that we will use to refer to the directory when assigning components. The Name attribute of the Directory is the name the directory will have in Windows.
We are also going to reference two more directories that use the Installer’s predefined names in order to place our shortcuts: the ProgramMenuFolder and the DesktopFolder, which reference the start menu Programs menu and the Desktop respectively. Within the ProgramMenuFolder we create our own directory for our application called “Fubar 1.0”.

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="WixTutorial" />
        </Directory>
        <Directory Id="ProgramMenuFolder" Name="Programs">
            <Directory Id="ProgramMenuDir" Name="Fubar 1.0" />
        </Directory>
        <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>
</Fragment>
The nesting indicates our hierarchy. This fragment tells the installer to create one directory named “WixTutorial” inside of our Program Files directory. This is usually C:\Program Files (x86). Note that Wix will not create directories with no components. However, the tutorial explains using the CreateFolder element in a component to create an empty directory (http://wix.tramontana.co.hu/tutorial/com-expression-syntax-miscellanea/creating-directories).

The second fragment that Wix provided describes our software components. The tutorial describes the component as the “atomic level” of thing to be installed. I think it’s probably more correct to think of it as the “molecular level” as a component can be composed of several VERY STRONGLY RELATED things, those things being files, registry keys, and shortcuts. However, as I mentioned before, it’s probably best to only have a single file in any given component. Only one file can be assigned the “KeyPath” attribute, the path that MSI will look at to determine if the entire component is installed. If the user accidentally deletes an installed file that is not the KeyPath file while leaving the component’s KeyPath file intact, that related file will not be restored by a “Repair” or even minor update.

The components are contained in a ComponentGroup element. This is a better way to put related files together without sticking them in the same component. Here we associated the ComponentGroup feature with the INSTALLFOLDER directory above meaning the components of the group will be installed to the “WixTutorial” directory. As directed, we’ll delete the comments that Wix put in and add our three file components to this group.

The first component is our main executable, FoobarAppl10.exe (I copied this along with the other components from the sample file download to my VS solution’s directory.) along with a Program Files shortcut and desktop shortcut. You’ll notice that I did not give the Component a GUID Id. As long as there is only a single file in the Component that GUID will be generated by the compiler. Each Component should have a unique string Id, however. I did not add a KeyPath=”yes” attribute to the file element either. The KeyPath will default to the single file within the component. Finally, I don’t have the  the DiskId attribute that the tutorial includes as that relates to the Media element that I chose to ignore for now.
For each File element there is a Name attribute. This is the name that the file will have when installed. The Source of the File, meaning the path to file to be packaged in the installer package, will default to this Name attribute. Since all three components are in the same directory as the Wix package I can just leave off the Source attribute.

The FoobarEXE file has two shortcuts as children. These shortcuts will be installed to the Program File directory and Desktop directory that we referenced when we set up the directory structure. Since they are children of the executable file, that file is automatically their target. The Icon attribute references the name of the Icon element to use as the shortcut. This name must have the same extension as the file that the shortcut points to. That Icon element (which I will add in a minute) can have the EXE as a source and the EXE can have multiple ICO files embedded within it. So you can add an IconIndex as the tutorial shows, but our executable has one generic icon and the index defaults to 0 (I believe). Finally Shortcuts can be advertised or normal Windows shortcuts. A normal windows shortcut just points to a file path and command and those can be changed by the user. An advertised shortcut is essentially more closely bound to the file. The link to it cannot be changed and if the shortcut cannot find the file it targets the installer will try and repair the installation and reinstall the targeted file.

We’ll add two more components the HelperLibrary and the instruction manual. The Manual also has a shortcut. This one has no icon so will just show up in our Program Files menu with a generic icon and the name “Fubar Instructions”.

I’ve added another ComponentGroup that we referenced above, the Shortcuts components. This component includes a RemoveFolder element and a RegistryValue element.  RemoveFolder is an element that you want to include if your application creates any directories that you want to clean up when a user uninstalls the application. Even though the installer is creating our ProgramMenuDir directory to hold our Program Files shortcuts, the compiler will fail unless we specifically tell it to clean up this directory on uninstall. My assumption is that because shortcuts are specific to the user profile that it needs to clean those up in a user-by-user basis. Thus we add a registry key for the current user that will be used as the keyPath to see if that program menu directory has been installed.

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
        <Component Id="MainExecutable">
            <File Id='FoobarEXE' Name='FoobarAppl10.exe'>
                <Shortcut Id='startmenuFoobar10' Directory='ProgramMenuDir' Name='FUBAR Tutorial 1.0' WorkingDirectory='INSTALLDIR' Icon='FoobarIcon.exe' Advertise='yes' />
                <Shortcut Id='desktopFoobar10' Directory='DesktopFolder' Name='FUBAR Tutorial 1.0' WorkingDirectory='INSTALLDIR' Icon='FoobarIcon.exe' Advertise='yes' />
            </File>
        </Component>
        <Component Id='HelperLibrary'>
            <File Id='HelperDLL' Name='Helper.dll' />
        </Component>
        <Component Id='Manual'>
            <File Id='Manual' Name='Manual.pdf'>
                <Shortcut Id='startmenuManual' Directory='ProgramMenuDir' Name='Fubar Instructions' Advertise='yes' />
            </File>
        </Component>
    </ComponentGroup>
    <ComponentGroup Id='Shortcuts' Directory='ProgramMenuDir'>
        <Component Id="ProgramMenuShortcut">
            <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
            <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
        </Component>
    </ComponentGroup>
</Fragment>
The final fragment to our file defines our Icon source for the executable. While the Id must have the same extension as the file that the shortcuts target, it does not have to have the same name as the file itself.

<Fragment>
    <Icon Id="FoobarIcon.exe" SourceFile="FoobarAppl10.exe" />
</Fragment>

Putting It To Use

At this point you can right-click on the project in Solution Explorer and do Build. Wix will ‘candle’ (compile) and ‘light’ (link) the appropriate files. If you go to the Project Folder and then bin > Debug you should have a new msi file. If you install this you will see the Installer fire up, show some progress and voila! Your application is installed.

If you go to your Program Files (x86) folder you should see the WixTutorial directory (or whatever you named your INSTALLFOLDER) and under it should be the three component files. In your start menu > All Programs you should see the “Fubar 1.0” (or whatever you named ProgramMenuDir) and under that the two shortcuts for the executable and instructions. Finally on your desktop should be an Icon for the executable.

You can remove the application either through the Control Panel or by right-clicking on the .msi and clicking uninstall. Uninstalling should remove all the files, directories, and shortcuts.

To Be Continued

In near-future posts I plan on walking through the User Interface, Events and Actions (which includes Custom Actions), and the SQL  sections of the tutorial. I do want to learn more about Upgrades and Localization and will post about that when those things become pertinent to what we are doing. I also want to look at creating both Web and Windows services and probably user creation in conjunction with that.

Sunday, January 6, 2013

when i wake up tomorrow

There was a point last year where I was searching for some motivation. I don't know if "motivation" is really the right word -- I was looking for a pep talk though, and I was the only one around to give it. I asked myself the hypothetical question: If you had only five years left to live is this the way you would want to do it? It didn't exactly change how I live. I still go to work everyday to a job that I probably wouldn't do if I really only had five years to live. Not to mention that I didn't even change my life insurance nor change my 401k contribution.

I have been more open with the pocketbook. We've booked a couple trips we can barely afford so far, and I'd still like to book that trip to France soon. I bought a new car. Okay, well that was more because I HAD to. We just put in a new water heater. There just is no point in going through your last five years driving a Jeep that is falling apart and taking too-cold showers.

So this isn't to say that suddenly I really am living like I have just five years yet, but I'm not living as if I have forever left to begin crossing items off my bucket list. I've actually realized that I have a bucket list to begin with and that I'd like to check off as much of it as possible.

Now what if that doctor who told me that I have five years left came to me and said, "We were wrong about the five years. You only have two left,"? Not 60 months anymore but 24, give or take 6 either way. What would I do with every single valuable day? It happens to people - not just older people, but young people - people my age with too so much life left it seems unfair they should have to squeeze it into 50 years let alone two. It isn't so much maybe about the legacy we leave at the end of our lives, but what legacy do we leave at the end of each day when we lay down in bed.

Thursday, December 20, 2012

M-V-P

There's been a bunch of talk on sports radio lately here in Denver about who deserves to be the NFL's most Valuable Player. Obviously the sentiment around here is for Mr. Peyton F. Manning. The Broncos are suddenly a top team in the league merely by the addition of Manning. Well, and the defense is also even better than what had been a pretty good team last year.

But have you seen what is going on with Adrian Peterson out in Minnesota? The man is going to single-handedly take the Vikings to the playoffs. Seriously, the Vikings don't have much else going on -- teams KNOW they have to run and AD is STILL putting up 200 yards a week at almost 6.5 yards per carry. (As an aside to the sports radio hosts around here, yes his initials are A.P., but the man's nickname is AD as in All Day.) It's historic. He's already matched Jim Brown for what was probably the best year a running back has ever had, and this is the era of the passing game. There are two games left. It will be great to see what he can do over those two games and if, indeed, he can get the Vikings to the playoffs.

There is the argument, particularly by the homers here, that a quarterback is more important, so that P.F.M. should win over Peterson. Again, I love Manning, but if you make that argument, then you have to cast your vote for Tom Brady, don't you? Brady has put up bigger numbers than Manning on a team that does not have near as good a defense. Broncos are an 8 or 9 win team without Manning. Without Brady I think the Patriots win only 5 or 6 games.

With the historic year that Peterson is putting up though you also have to make mention of Calvin Johnson and the year he is having. He is even closer to breaking Jerry Rice's receiving yards mark than Peterson is to Dickerson's rushing record. Of course, as I said, this is an era that favors passing over rushing, but still what Johnson has done is pretty remarkable given that the Lions don't have a lot of other options on offense. Megatron makes these catches that make your jaw drop like watching a Barry Sanders run. I've never seen a man so routinely beat double coverage. Teams play man defense against him and put two men on him. Teams have put THREE men on him to try and cover him. I've really never seen anything like it.

All this said, if I had a vote for MVP I'd give it to Brian Urlacher every year, if he coudl stay healthy. I know as a Bears fan I'm biased. However, the Bears are a completely different team without Urlacher in there. They are a winning team with him and a losing team without him. It's that simple. Every year though we witness how badly the Bears can play wihtout him because it seems that he is out for at least a handful of games every year.

Tuesday, September 4, 2012

Killing a Chicken


I had to kill a chicken this morning. I know to most people this doesn't sound like much. Seems like everyone has some tale of watching their grandmother or great-aunt or someone chopping the head off a chicken at the family farm and then watching the thing run and flap around.For me, this was sort of a pet, however, and it's really rather painful to take the life of something that has relied on you for food and shelter.

Last week I noticed the Diva was having trouble moving around her pen, as if her one leg were hurting, though there was nothing visibly wrong with her. Though I purposely did not name our chickens so as not to grow too attached to them (especially after the dogs attacked and ate our first batch of pullets), our bantam golden seabright earned her monikerby acting bigger than she was. I hoped it was a minor injury. The next day she seemed worse, not wanting to leave the nesting box or move much at all. I had to make a decision regarding taking her to the vet. Like I said, to me the chickens are "sort of" pets. They rank somewhere between our dogs and the goldfish in our backyard pond. They don't have names, but I've committed to taking care of them even after it turns out they haven't been the best egg-layers. I've said that I don't want to end up running a retirement home for hens when they stop laying, but my threats of putting them in the stew pot have been pretty empty, not to mention then hens don't lay any better when faced with such threats anyway. So while I had some concern for finding out exactly what was wrong from the vet, I also told myself that if I am going to take care of chickens I will also have to face being able to take care of one, one way or another, when they are sick.

The next day, and perhaps this was only wishful thinking, the Diva seemed better. She was out of her box voluntarily, and while still tottering around sort of hopping on one leg, she was eating and drinking. I really did have hope she was going to get better. Over the next two days, however, I saw it was just an illusion and my hope in her recovering turned to hope that she would pass peacefully. I had to help her out to get to her water, and she stopped eating except for a little leftover cooked corn we had. This morning I found her outside the box laying on her side, unable to get up on her own.

I knew what had to be done. I had read about the quickest, most humane way of killing a chicken that you intend to butcher by wringing its neck. I've seen the debate online of whether an axe is better. I frankly didn't think I could use a hatchet without causing undue stress on us both. Not that I intended to butcher her either, I just mean that I am sure a vet could administer some injection to kill a chicken, but for me and my aspirations of one day actually being a gentleman farmer, that wasn't practical. The Diva had suprisingly been the best layer of the first three hens we got, the other two being Welsummers which started off laying well but have been terribly inconsistent the past year. The little seabright's eggs, too, were surprisingly large in comparison to her little pigeon-sized body. They would probably qualify as USDA 'medium' sized eggs. Well now she was going to provide one last gift: my first lesson on killing an animal I had raised.

I picked her up and held her close to my chest, which calmed her. I held her like that for a moment to say a goodbye then tilted her head-down. Inverting a chicken like this will calm them, and I'd done this before when wanting to check her for disease and injury. I took her whole head in my hand, and she pulled it back away. For that one instant I wasn't sure that I could go through with it, but I couldn't leave her in pain. I grasped her hand a bit more firmly and with a little surge of violence twisted. I felt the bones in her neck break and she gave a quick kick and stopped. I let go of her head and looked at her. Her eyes were open. "Oh please tell me you're dead," I begged in my head. She blinked, but otherwise did not move. "Dammit." I twisted again and pulled down quickly on her head. I had been afraid to really yank before, afraid that the head would come off. This time, though, I felt the spinal column separate, and with her head still on she was dead. She kicked for about 20 seconds then. It was a rhythmic spasm that was obviously simply a nervous reaction, but I still held her against me. It stopped and I looked and all the color and life was gone from her.

She really did look at peace. I felt horrible that her death wasn't as quick as I hoped it was going to be but am convinced it was painless apart from that initial kick. Even writing this account, I didn't want to admit that it took two tries, but I feel like this was the lesson she gifted me with and that it would be better to share the information so that other people wouldn't make this same mistake.

It's sort of an empty feeling to be putting something that was alive moments ago into a body bag of sorts, as in a gallon-sized Ziploc-brand bag, and then into a shoe box to bury. I think that empty feeling is appropriate -- a life has gone out of this world, and I'm the one who took it. In that bag and then in the box she looked like a fake bird, something you'd find at the hobby shop to add to your homemade wreath. I'm glad though she isn't suffering and also that my emotional barometer seems to be calibrated correctly: I'm sad she is gone, glad she didn't needlessly suffer, humiliated that I didn't get it done right, proud I could do it at all and confident that in the future I can... that I can kill a chicken.

Wednesday, August 22, 2012

A Personal Message from Citicards

A personal message to me from the CEO of Citicards:

Dear Benjamin,
I’ve always thought that the best way to show someone you are listening is to really deliver. That’s why we’ve been listening to customers like you, and making changes in response to your feedback.
For example, you asked for a monthly statement that is easier to read and use.We listened. Over the next few months, you will see a new statement, with a simplified design and a standard paper size so it’s easier to file.
You also asked for a more timely view into your spending. We heard you. Now, you can see your pending charges online, before they post to your statement.
You can read more about improvements we’re putting into place at my blog. Please stop by so we can continue the conversation and make your experience with Citi even better.
All the best,
Jud Linville
CEO, Citi Cards

My Response:

Dear Jud,
I don't freaking care about a new statement format. Lower my freaking rate or I'll just continue to NOT use your card. We taxpayers bailed out your company and yet you continue to fleece us with your excessive credit card rates. I simply won't carry a balance with you. Don't bother sending me your new and improved statement at all, since I guarantee it will always say $0 regardless of how exorbitant the rate you want me to pay.

Sincerely,
Benjamin Rice
customer since 2003

Wednesday, August 8, 2012

Ate, ate, ate-ey ate.

Every year on this date I am reminded of a particular moment in my life, one that maybe only seems profound to me now in that it is so memorable. It was the eighth of August, 1988 - 8/8/88. I was attending the Center for Talent Development (CTD) at Northwestern, now affectionately remembered as Nerd Camp, still a few weeks from my 14th birthday.

In this particular moment burned into my memory I am standing outside Scott Hall in this little triangle where Sheridan Road, Chicago Avenue, and University Place come together, across Sheridan from where the Northwestern Arch now stands. It's dark out so must have been after nine at night. It's raining and I'm unfolding a Tribune that I had bought to put over my head. There's an insert that is a special for the Cub's first night game at Wrigley. That's what makes the moment stand out to me - I remember thinking how clever it was for them to have the first night game on 8/8/88. I guess I can't think now why that would be so clever; maybe it's just because then it would be memorable to people like me.

I wanted to go to the game. A group of fellow campers did. I couldn't afford it. I had worked mowing lawns to help pay to be able to go to camp for the second year and spend three weeks outside of Chicago taking basically a high school AP algebra course. I think it must have been around the end of the session, because I know I was down to the last couple of the American Express travelers checks I had gotten with my dad at Wolverine Bank in Frankenmuth. I wanted to have some money left over for souvenirs for my little brothers, not to mention the Charleston Chew bars I'd get each day during break from class. So I passed on the game.

It was rained out anyway. I guess they got a few innings in, but the first official night game at Wrigley wasn't played until the next night. I remember those who did go to the game later describing how the players came out and used the tarp as a big slip-n-slide. In that one moment though with the rain and the paper and the cars going by on Sheridan I was giddy. I literally felt on top of the world. I remember thinking "My parents don't even know that I'm out here at night in the rain." I wanted to stay there. I loved Chicago, loved Evanston and Northwestern and my classmate-campers who were the coolest, smartest people I had ever met.

Everything changes and everything stays the same. There was another profound moment that I remember from that summer. One of the teachers at CTD gave a lecture on the relativity of time and multiple dimensions. Time being the "fourth dimension", as he described it, blew me away. I am now 24 years and 1000 miles removed from that moment in the rain. I have those moments of that summer, along with many others from CTD and millions of other moments including several others in the rain along Sheridan Road at Evanston over these 24 years. It would be sweet to taste just a bit of that feeling of being on top of the world again. You can't turn back the clock. There're lights at Wrigley now. It's for the better, they say, because now they have 28 night home games a year.