Working with the WiX Toolset — SVNUG Presentation 31

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well welcome today I get the chance today of introducing Keith rye Kirk which is somebody I think a lot of us know I've been with him or worked with him on and off now for a number of years and there's certain types of projects where you get to really know somebody the kind of projects where if it's a Saturday night midnight and you're working if it's a Sunday most of the day and you're still working we worked on a project once where the schedule was pretty aggressive and then all of a sudden it got tripled in size and the schedule got pulled down by a factor of two which means things got uncomfortable and there was an awful lot of work and Keith's the kind of guy that just digs in things get uncomfortable he digs in and goes and figures it out and sometimes it's a little things that can make a different difference in a project and he's always been a good one to dig in and find out the details no matter what it is now Wix is one of those things that you kind of go what Nick is it well if it's Microsoft is probably with XML of some sort they love XML and if it's installer stuff is probably XML kind of generated junk now that's my guess because I don't know much about Wix I always depended on Keith to do that kind of work so if he embarrasses me well that's okay Keith this is one of those that commutes in the Springfield area from quite a distance his two children and a wife who can be sometimes feisty she seems pretty nice and he has worked and everything from like little mini mainframes all the way up through probably visual basic kinds of things and doing C and video types of things and now he's working in pension gold at LRS so I'd like to give a welcome to Keith's record thanks mark okay like Mark said you know what really is Wix sure unless you've had to be on a project where the last minute you found out you know what we need to make sure we have an installer for this thing we've been building you probably don't know what it is but I'm going to try to enlighten you a little bit tonight and get into some of the basics that will help you build your first Windows installer infadoos so a little bit of background Wix has stands for Windows installer XML it was Microsoft's very first open-source project and has recently been moved off to the outer curve foundation it is a replacement for the old set up and deployment project type in Visual Studio which if any of you have had to work with that and and maintain the project that used that it can be a real real pain it makes it kind of nice because Wix that makes it pretty nice because they give you templates that you can use within Visual Studio to build and maintain your installer it does require Visual Studio 2005 or newer hopefully you're not still stuck on those but if you are I'm sorry there's some somewhat decent fits there's some fairly good documentation out on the Wix site which you can get to a Twix toolset org it is open source so besides that there's you can find a lot of blog posts and you know a lot of different entries out there the problem is comes down to finding answers to particular problems you might be having and there's a lot to it so you can you can kind of get overwhelmed if you're not careful but I would highly recommend if if you have to do any build any installers using Wix to go ahead and pick up this last this book here by Nick Ramirez I wish I would have had this you know six years ago when I first started using it because it really lays out the guts of what you need to know to get going with it and it goes deep too so you can start out not knowing very much and progress to some more advanced topics in there all right now there's some pros and cons to Wix number number one Pro is it's free it's open source so you don't have to go get permission from your manager to to you know for a purchase request for this you can get it install it with Visual Studio it's open source and the community behind it is actually very active they've taken Wix and extended it to multiple platforms but multiple like trouble areas you might have during an install for for example sequel server if you need to run any sort of sequel script during your install there's an extension out there for that that can help you do that you don't have to worry about creating your own custom deployment actions and try to integrate those in there's a lot of nice extensions for that like I got here you know sequel is PowerShell all extended on to the base which toolset one of the big bonuses that I have come out with this is the fact that it is source controlled friendly it's all markup so it's all XML defining what your output windows installer should look like now what that means is that whenever you make any changes to it and check it in you can go and do a diff on those and see what changed when makes it really really nice for tracking down installer problems which usually come it you know or go live date is tomorrow and Oh has anybody tried the Installer huh no let's try it out now and you know so you kind of track down the problems who put in the bug and and chastise and for to that at that point now the cons to this is there is a slight learning curve and like I said it can be difficult to find the documentation you want online and also if you're wanting to develop for anything but windows you're out of luck here it is Windows installer so you're building windows and stores all right I'm going to jump in and show you demo now all right and what I've got here is I've got a solution with four projects in it well five if you count test these bottom three are my application that I've built and I want to go ahead and build an installer for it so I would go to you know add new project and in my templates I've got a setup project right here for that so go ahead and put in the information need and add it end up with this right here now the guts of this there's not much to it really it may look not look that way to you guys right now but there really isn't much to it in essence what you know all this markup is defining what your windows installer needs to look like what properties it needs to have on it what contents need to go into it etc product is defining the actual product that you're installing makes sense so in this case the name of my application is SB nug Dental app what version it is who the manufacturer is in an upgrade code now if everything on that on this product line the most important thing to understand is upgrade code between versions so I have version 1 of my demo app out there I built an installer this is the upgrade code that goes with it I go ahead and I implement new features and update my version to version to upgrade code does not change this is what's going to link any previous installs to your new install to make sure that those are apply your changes are applied over top of it so you so it will see it as the same application package information this is a this is information about the Installer itself most of this you can ignore the most important part here though is install scope this is going to tell it to either be installed per machine or per user and OneNote 1 gotcha that I found is the the default for this is per user so if you leave out this attribute your install is per user no matter what if you then catch that on a later version and say you know what these let me to always be per machine anytime that it goes to upgrade it you're going to end up with two installed versions on that machine one that's installed and per user one is per machine so don't don't do that so it's a pain to try to clean up the rest of this is just you know different additional information about the Installer itself the MSI package major upgrade this defines you know what you know what do you want to show when you've already got a newer version installed somebody tries to install an older version media template it's defining the actual files that you add to it are going to be placed in the cab file if you if you leave this as embedded cab know it'll go ahead and have your MSI file and then a separate cab file layer along with it if you go ahead and set it to yes it'll include it in the MSI so you'll have just one file for your install if you need to do anything on multiple discs you'd have to set this up and do a little bit more work of defining which files go into which cab so you can then have those placed on different disks maybe hopefully not to mess with that you define features for your installed my case we only have one all my components are going to be installing the same thing but if you need to set up your install with a selection for okay I need all the base controls plus these additional logging features or something as separate you can set those up as separate features and have it only deploy what you select you eye now out of the box there's there's a few different options for this I'm going with the very basic one it's going to give you the selection of whether or not you agree with the terms show your you know little legalese on there and then continue with the install there are several other ones you can do and this is a list of them mando is everything under the Sun it'll have where do you want to install it what set a feature do you want to install from this all that stuff built into the UI for it but to get started definitely use minimal it'll it'll help you get used to what it's doing so directory you set up your directory structure in here target directory has to be the root of this every time and then nested within it you would more than likely have Program Files and then the name of your install folder within there where you want to go so in this case in the install folder or in the program folder I should have an SP no demo app subfolder that contains my deployed app don't worry about this fragment stuff right now we'll get to that in a moment but component groups component group contains components every component has to have a file in it one key part to this is you can have multiple files in a component but you can only have one file that has key paths set to yes what that does is when you do a repair when you go ahead and run your installer something's wrong you want to do a repair on your installation the only files that get redeployed are the ones that have key path of yes so if you try to get fancy and say well I have this one component that's really you these multiple files you could be really messing yourself up because only one of those is going to be redeployed so you lose the other ones or end up with one of those being the one that's actually bad that should have been replaced and that's kind of the that's the guts of it there's nine files I think here that get deployed when you build this we go out and take a look at the output of it I end up with a MSI and then I have a PDB for the for the Wix symbols themselves all you need is this MSI to actually run let's take a look at what it looks like so this is this is that default minimal UI that comes with it out of the box and get this pretty logo in here all this can actually be changed as well you can set what you want to use for the banners and all this stuff and I go ahead and I say accept install it yes I'm sure runs through Dunn's a bunch of stuff in the background and says okay I'm done now this one was so basic I didn't even have it create a shortcut for me or anything you can do all those sorts of things you would expect but I go out to my program files take a look we should have the output in there right here there's my SP nug demo app under Program Files and there's all my deployed files in there this is the app now the best way to the best way to learn this is to start off small in fact when I when I first when I created my very first installer it installed a text file that's all it did just figuring out what all the different XML meant within there and what the gotchas are it's kind of how I don't have to go about it go back to the slide real quick here some key things to take away from this product these all these are the different tags for your XML product tag the ID leave the ID as star it'll automatically generate it any time you build and never change the upgrade code unless you are actually wanting to have an upgrade where you're no longer compatible with the prior version package the install scope faults the per user that can get you more than likely you're going to want to set the per machine at least in our case that was the requirement embed I said with the embed tags the the UI extension now in order to get the decent decent-looking UI for that you have to go ahead and import in an assembly one of the extension assemblies take a look here Wix UI extension that's part of when you install Wix it puts all those assemblies out there you can just go and add reference to that assembly which then gives you the ability to set this UI ref so just by adding that UI rf2 ID of minimal is what allows you to change the look of it if you don't put that in there and you don't go with the of one of those you eyes you end up with an install that just comes up and says you know go ahead install and it just done it doesn't let you know anything you know just going on components and file like I said with the key path the rule of thumb is only have one file per component and the other thing that I didn't mention but it can help you out down the road is your naming of the components if you go ahead and prefix the components different from the file and then use the rest of this to just name what the file is see here where my source is getting it so the name of my file is actually part of the ID that helps if you have to track down any problems after the fact so I believe that that is pretty much it oh if you do have problems the Windows SDK there is a tool called Orca exe I think it stands for one really cool app anyway what it allows you to do is go ahead and open and edit an existing MSI file you can see all the tables that are in there that's where the naming of those components and files helps because you can look in the table and see it match up to what you named it instead of some of the faults are like goo it's trying to match up a good you don't know what that is so I suggest getting a hold that and don't do like I was just doing where you test it by just running the install on your development box because if the if the if the install dies in a bad place you could end up with registry entries that are orphaned and if you run it like a bunch of times trying to figure out what's going on you could have a whole list of programs that are supposedly install the windows think cesare installed but you can't get rid of so use a virtual machine and there's also a way to turn on logging so whenever for your install itself I have a script for this if you guys are interested let me know which turn it basically turns on the logging runs your install for you and then after the install is done it turns it off so you don't ever forget and then brings it up so you can see exactly what's happening within there so yeah a question on that is you said that there was debug symbols can you actually step through and debug the install process yes you can yes you can well logging might be just as good yes logging for these typical ones logging was always more beneficial for me anyway when we get to part 2 over the bootstrapper you can you can debug right into that as well I have two questions actually first of all can this create exe files in addition to the MSI for installers those are just MSI's the typically your exe SR a bootstrap okay that that are you run that and it kicks off and then runs yours right I'm not sure you might actually be able to do that as well but that would be in the properties look at there there we go yes you can you can create MSI's merge modules Wix libraries this is essentially a replacement for merge modules you can set up a core set of components that you need to install like you would a merge module and then pull them in on your next Wix project just by referencing the library so and then my second question is on the components in your in your project did you have you did you have to create all that by hand or did was there tool to help well pull in all the components and yeah let me let me show you all that information let me show you what happens when you actually fire this up so if I do a new project now I go to the Wix installer and I select my setup project create a an MSI based installer it puts the majority of that product file in there for you so you can see here and it gives you some information component groups this is where my components go insert files you know all the other stuff there the basic for my directory tree as well as a lot of the information here if I try to build this now yeah manufacturers never showed up so you get a sorry drop-off so it tells you you know you can't build it without setting the manufacturer anyway thank you hey Keith I have a question about the components in the XML no you said can you go back to that you said you prefixed all those with like cmp underscore fil so you had to go in there manually do that or could you tell it to prefix everything um you know what there probably is a way to do that there is a tool that the Wix tool said there's a whole set of different pieces to it one of the tools is called heat which what it allows you to do is you can you can take it and run it against a directory and it'll take a look at that directory find all the files that are in that and generate a fragment so so it could basically generate this fragment right here there's a lot of different command-line arguments you can put on that to tell it okay I need it to create goods for each one of them or I need to you know different naming type things like that there may be a way to do that as well where you or you have it prefix it as well but I'm not positive on that there's a lot there's a lot that it can do that you don't know until you need it oh that's something else I should mention there's that heat tool there's another tool I believe it's harvest it might not be the right name but you can take and have it generate the XML for you code for you from an existing MSI file so it'll take a look through there and give you a fragment of what's all in there which is useful it's useful for figuring out you know what this is a pretty did a pretty good job on this installer how did they do some of this stuff you can do some reverse engineering there's typical ones I'm not sure about typical I know that majority of the time when I end up with an installer that fails it gives you some error message that means absolutely nothing to you and you go out and try to find it the majority of the times that I get that I fire up the logger to go ahead and log wallet installs and then you know backtrack as far as where I find there was an error and see if it makes you know see if I can find where in my wits code that's could have been coming from or where it's near anyway trying to think of some of the actual problems that had to track down when using the extensions like when you are using like the sequel extension to run a script on the database database connection could be a problem you know network your network is too slow Orr's down when you try to run it when it tries to resolve the the server and stuff what stuff along those lines the logging the error message that comes up for that is not useful at all but the logging actually helps track that down that's a good question for the most part yes I have seen times where the my assumed order is switched because for one thing you don't have to have it all in one file essentially any these places where you have a fragment you can set that in another file and when you have those sort of things happening it doesn't load any of the contents of that until it finds a property in here that resides in there and that time it'll then load it in so I think some of that can change the order in which that stuff have occurred but if you do have issues where you have to have a specific order for things the majority of these have attributes on them for we're not component maybe some file there's a condition hmm don't believe it somewhere in here there is a condition attribute so you can basically tie that to you know whether or not if it is found that you know this file exists or you know based on those sorts of things so you can you can do some of the some of that too you know set the order in which things occur it's probably on the feature my guess else all right thank you next thing I want to talk about is one of the additional features that has been added to Wix in the latter versions for creating a bootstrapper now bootstrapper for those of you that don't know is a pre install process for installing any prerequisites that your primary application might need so if your application needs to have sequel server a local instance of sequel server installed you would have to do that in a bootstrapper before it before you run your application one of the problems that are well one of the challenges I guess to creating a nice installer where you have a lot of prerequisites is to make it look professional when you've got ten different prerequisites that have their own install so they have a different look to them you know very disjointed when you run it and it pops up and says okay I'm going to install the C runtime now and then that kind of goes away and something else comes up it looks completely different that's installing sequel server or or some third-party components or something along those lines the the wicks bootstrapper it uses it another one of the tools within there called burn and what it allows you to do is have a unified look to your install so it when you when you run this bootstrap it looks like this is just my install it you don't care about you know it's doing all this other stuff behind the scenes to get prerequisites installed just looks like you know you have a single experience with it it has correct they created a new project type in Visual Studio for the bootstrap and it allows you to chain multiple installs together so I have my product install I have a install for sequel server I have another install for some other component all these different MSI's one of the limitations of the MSI install type is that you cannot launch another MSI from within it the bootstrapper is how that you get around that so this it's kind of like managing or orchestrating your list of installs that you want to run so the different supported types you can have an installer to chain in that's an MSI or another executable they can be patches msps or updates the msu install type all those are supported in the box with this and one of the really nice things about what Wix has done is they allow you to customize the UI itself and you can use WPF to do that so that's right up my alley as soon as I saw that I thought wow there's a lot you can do there to make it you know really nice so go ahead and jump in take a look at some of the code for this all right so my my solution has two projects in it bootstrapper which it's created and let's go ahead and do this right off the bat this time by doing a new project and under your windows installer XML there's a bootstrapper project type and let's put that not in the same place and that gives you kind of similar to what if you're building a set up it's going to go ahead and shell out a bunch of the mark-up for you very similar bundle it's describing the actual bootstrap itself information about it so you can version it upgrade code works similar to that as well so you can upgrade as you go you want that to say stay the same so you can sort of knows how to match them up on the reinstall the bootstrapper application ref this is telling it what you I do I want to use for my bootstrapper the default is this RTF license so it looks very similar to where it comes up it shows you the license information you say I agree and it go on so it looks very similar and then chain this is where all the money goes this is where you put in a list of all of the different installs you want and the order in which you place them in here dictates what order they get installed okay let me jump back over to the live one ignore this for now and ignore that as well so so here in this example I've got two prerequisite installs that I want to run prior to the install that we just created okay so it's going to run through it's going to do pre req 1 followed by pre req 2 and then get to the one that we just created you'll notice here that the bootstrapper application ref has been changed it's no longer that RTF licensed managed bootstrapper application host by setting that value for the ID it's telling it I want to use WPF as my front end for my UI I'll get to the rest of this here after I show you the other project the other project in this solution is it's just a c-sharp assembly - dll this has my my view code in it okay so if you're familiar WPF I've got my I'm using the MVVM pattern I've got a view and it has a view model that it binds to to get you know any changes for value any values that you want to display and the view model hooked up to a model that has any underlying you know data access you need to run or anything like that now in order to to get the okay so in order to hook this up to the managed host one of the requirements is you create a class in your custom UI assembly that implements this bootstrapper application that comes from there's a reference that you get to an assembly called bootstrap or core that comes from Wix itself when you install it you add that reference to it you can now override the the underlying bootstrapper application that drives the actual install process okay in here you'll notice that there's only one override on this class it's needed and what we do is we we want to for WPF a lot of times you need to get ahold of the dispatcher that's the the thread that is the UI is running on so if you have any processing going on the background that you run through it and then based on an event need to update the user interface from a separate thread you need to go ahead and VOC that on the dispatcher so we go ahead and grab ahold of the dispatcher that the UI is running on so we can do that easily from any worth in the app the rest of this is just simply hooking up doing WPF hooking up your model view and view model I'm instantiating a model show you that here in a minute I'm instantiating a view model Stan shooting my view and I'm setting the data context on my view to that view model so that's going to allow the bindings to work through there and them all I'm also doing a little bit of a hack here to hook into the closed event on the view itself on the window that when that happens I want to go ahead and tell the underlying bootstrapper application that hey I'm done I'm canceling I'll kill it so not just close the window and I still have that running in the background the rest of this is kind of boilerplate for your instant for the bootstrapper you need to grab a hold of the window that the view is running in it uses that for passing it on down below to the bootstrap application detect this fires off set a code to make sure that the installs that you are going to be running find out if it exists or not so in this case we want to make sure that our application isn't already installed on there before it tries to you know install over the top of it and then the rest of this is just go ahead and show the view and run through it the model the constructor for the model you're passing in the bootstrapper application okay what that gives us access to is the underlying engine of the install itself and kind of the steps that occur when the bootstrap runs is you tell it okay I need to plan for an install of this product so it runs through and it evaluates that MSI and okay these are all the things that you know what passes the requirements to install it following the plan there's the actual execution of it so it's you plan it then execute it or I'm sorry plan then apply it but that's really what it's doing it's actually executing it so what the model is doing here is wrapping those underlying method calls for plan of a particular action and applying whatever action you had planned it's you know wrapping them for you there's also a nice log that you can hook into so that you can send messages that get logged out to the Installer log as you're going through all right my view model is actually pretty basic I've got three commands got my install I got my uninstall and cancel I have to keep track of what state the install is in which I'm using this inu to do whether I'm initializing present and non present is what it uses to determine whether or not I can install or hey it's already there my only choice is to uninstall it applying is when it's actually you called apply so what's doing its work cancel of course is you've clicked kick cancel or some underlying problem occurred and it automatically cancelled so it'll drop out I've got a property for message where what I'm using it for is just to show what my current state is state of course the - any time it changes you have to run through and change it and I tried to hook up an overall progress to it as well nope the problem with this demo is is that I don't have enough going on in the installs so it gets done too quick to show the progress I believe I think that's what's happening at least so maybe I figure out a way to do that at that point my constructor from my view model I go ahead and set it to initializing when it starts up I wire up the event handlers and I initialize my commands this is very typical of WPF the wire up is setting up event handlers to the underlying bootstrapper application so it's basically my using its wrapper to go ahead and hook you into the underlying event to go ahead and capture and you know process what's going on at that point that's whatever one of these it does and initializing commands it's very similar I've got what do I want to do when this command is run and you know can I actually run it so on the install it will only allow you to install it or show the install as being an option if the install state is not present so it didn't find it there already similarly the uninstall has it only if it's present all right I'm going to shut down this is hooking into dispatcher to go ahead and kill it all right let's go ahead and and build this take a look at what the output looks like all right so I got my executable bootstrapper executable now this this project also has the ability you can select an msi as the output type of this I think that might be an oversight in in their template because if you try that it tells you you have to have a package it's looking I think it's trying to do an actual just a regular install at that point instead of a bootstrap but if we run this now you'll see my UI beautiful UI my install uninstall is grayed out because it doesn't exist and I'm like I might cancel and a nice progress bar that doesn't show you anything at this point the state of it showing what the state is you wouldn't do this in yours but it helps to kind of debug figure out what's going on saying it's not present so that means that which buttons are available makes sense all right so now when I install this acts just like a regular installer it's applying so I can't click either of these it's done now take a look at what it what actually happened if we go and look in programs and features you'll notice right here we have one entry for SB nug demo tool set that's that that's the name I gave the bootstrapper and there aren't any other ones in there so those other two prerequisites and even my app the application we built don't show up as separate entries in there you can change that you can have Maul show if you want as separate but this allows you to go ahead and have your the installs that you have bundled together can actually be managed together so that if I go and do an uninstall it can go through and uninstall all those as well so now if we come back and we oh let me show you one other thing real quick here if we take a look at program files I've got my two prerequisites so they show up as you know where they're install said they should go I didn't show you those that's where they go and then the demo app shows up just like it did from the MSI that was in there so it doesn't create just a single folder doesn't have to do any kind of a directory matching or anything in there alright so I go ahead and fire this up again okay now I can't install I can only uninstall because it's already there fired up does the same thing now the entry from programs and features is gone and the files under Program Files are gone as well so I've got rid of all three of them so now unfortunately that's all that I've got to show you for tonight I did not get to do is throw a job on this as I'd hoped I'd hope to actually have an application that run install for this that looked more like a typical professional install to habited trying to figure out how everything was working took more time than I expected so there any any questions on this all right thanks
Info
Channel: svnug
Views: 55,510
Rating: 4.8085108 out of 5
Keywords: Microsoft .NET, SVNUG, WiX, Windows Installer, MSI, Setup Bootstrap
Id: XfwlWUJPmYU
Channel Id: undefined
Length: 50min 11sec (3011 seconds)
Published: Sat Nov 30 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.