C# Desktop App Deployment with Squirrel - Easier than MSI Files, Better than ClickOnce

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
deploying your desktop software isn't the easiest thing to do well either you go the simple route and just copy your files to another machine or you try create a complex installer file that's hard to understand and support fortunately there's a third option in this video we're going to look at squirrel a simple to use installer that just works we're going to see how easy it is to create an installer that also keeps our software up-to-date without being a huge headache but first if you're new to this channel my name is Tim Corrine it's my goal to make learning c-sharp easier sometimes that comes in the form of free videos like this one other times it comes in the forms of challenges that encourage you to push yourself those are released every Thursday here on this channel still other times if you want to see how to put things all together a course might be the right solution for you those are located at I am Tim quarry comm for these videos if you're looking for the source code or for more resources follow link in the description to go to this videos blog post ok let's get started in visual studio if you watched my video on sequel light this source code probably looks confident in fact it's a direct copy from the end of our sequel light demo video so if you get the demo code for this it's actually the end of the sequel light demo so that's where we're starting from I just want something to get started that had a little more complexity than just a basic wind form application now if you're not familiar this equal light or if you don't want to be that's fine you don't have to be this video is not about the actual technology used in this current application I just wanted to have something that had a class library that had a few more references than normal so we have like the reference to sequel light and in fact there's also some files they'll need to bring as well but what we're going to do with this source code right here is we're going to make turn it into installable executable in fact I create at both installer and an update err and then what we'll do is we're going to update this source code after you deploy it after you installed it we're gonna update the source code to make it change and I'll show you that change is gonna be it's really simple but right now if we add a person to this list it is not refresh the list until we hit the Refresh list button we're gonna change that so that when you fill this out and hit add person it's going to add the person and refresh the list so I just say test user and we're a hit add person notice nothing happens but if I hit refresh list test user is now there so that's our current form we're going to create the application installer now and then once we're done we're going to update this application and see how the updater works the other tweak we're going to do is right up here it says sequel like demo form by Tim quarry I'm going to add in here the version number that way we can also see that the version has changed okay so those are two things where I'd modify our actual base application besides adding the installer stuff okay so those are kind of bonuses that we're going to do just kind of show off what the installer is actually doing but let's first start by talking about what squirrel is so normally think about installers we think about setup to exe files or MSI files or maybe even click once those are the typical installer type files the problem is that MSF MSI files and Exe files are somewhat complicated create and there's now really great easy to use package out there that that I have found at least and now hopefully there is guys have missed it and if you find one that you really like let me know and I'll see if may other even a video on it but usually what happens is they are less than full-featured if you want the full featured version you have to pay for it or things like that and so I just not found a great tool especially not for also keeping your application up to date now you can just distribute your exe files and DLL files and that kind of works but only if they have a dotnet framework installed and only if there's a couple other things that that go along with that especially dependencies that you have to worry about and they don't update themselves so the person behind squirrel said I just don't like these options click once has some problems Exe S and MSI files they have their own problems and so what he did was he created this tool called squirrel and squirrels goal is to meet the 80% of you use cases that means there's going to be some things on the edges that it doesn't doesn't do and if you really need to have those things done you have to go to the msi level or there's some other tools just coming out from Microsoft that will help but I'm gonna cover those in a future video but for the 80% which is I need to install an application put a desktop icon on have a Start menu icon and allow it to both run and update itself that's what squirrel does and the really cool thing is you almost don't know it works because it's just so seamless and behind the scenes what happens when you will see us we install it but what happens with the installer is it doesn't ask you any questions you just run it and launches the application and behind scenes West does is download it put it into your app settings I believe wrap data one of those update I think folder which means it is not need to have a prompt there's no UAC prompt which is that security prompt for elevating permissions you don't need to do that it just installs behind scenes and it just runs and then the highest scenes you are running your application it can download a new version and then the next time you run your application is just a new version there's no nothing you need to do it just works so there's really really a little almost no interaction the user has with the Installer they just think it just runs and it works which is really helpful so let's look at the github page us is open source so it's on github slash squirrel slash squirrel for when dot windows and this is it's like click ones but works which is a great tagline so what this does is it's this creates our installer for us so we're gonna walk through the process today of how to use squirrel we're gonna use the basics but if you want some more information more in-depth stuff and there is a lot of add-ons or other tools you can use with squirrel to make you even easier then you can come here to github.com slash squirrel slash squirrel dot windows and then look for more documentation or for more add-ons now in the future we're covering an even easier way to use squirrel alive what we'll do today is going a manual process we're gonna manually create some things and manually change some version numbers and those type of things there's ways of automating this to make it super simple to do but I want to show you how it works in the manual process first and then in a future video I'll show you how to automate these things that way you have an understanding how it works so if it breaks you can fix it but there is ways to make it easier because it it does have about five different steps in order to deploy a new version which is okay but you really want to have those five steps automated especially since they can be so we'll talk through that as well but for right now let's start with the basics so step one is on our winform application we're going to right click on references and say manage NuGet packages and we will add a new one squirrel dot windows let's search for that and select it now notice there's a lot of others squirrel packages out here if you wanna integrate with a cake or top shelf migrating from click ones to squirrel lot stuff out here for those type of things but we're gonna do the squirrel dot windows the latest version right now is 1.9 so hit install on that and once that's done installing we can go ahead and close out the package manager now the next thing you want to do is we want to create a place where the update runs and so this is gonna be it is going to be the place that checks for a new version and if it's there it's gonna download it and install it which is really simple we want to do it somewhere at on startup which is typical now if you don't want your application to always update if you want to a manual choice you could create a button for this but we're going to assume that you always want your application to update now in a wind form application technically program CS static void main is where the application starts you could in theories kick off the update right there we're not going to instead the form that first starts is this people form and so this is really the the visuals start of our application so behind the scenes in our people form we have the constructor where we first initialize the components then load the people list and then we're done loading the form so what I'm gonna do is we're gonna create a new method in here let's say private async I don't want to be asynchronous we're going to return just tasks and say check for updates so this is our update check and what we'll do is we'll actually hold this after we load the people list and in here we're going to make a call to check for updates okay using statement inside here we'll say var manager equals new update manager we'll do control dot add a using statement for squirrel and then in here we're going to put our path to where the updates we found now this is a the tricky bit okay I'm going to put a place on my local hard drive and the reason why is because we're going to go simple in this first video I'm gonna get into more complex things in future videos including pride a better way of doing this which is to put your updates on a web server somewhere that makes more sense however when you're first getting started and your first creator first application or first installer you don't want to spin up a whole web server just to have updates for your little test file okay and if this were a corporate network you wouldn't need a web server either because you would just put it in one location that everyone has access to so I'm gonna put it into a location I'm going to pretend everyone has access to who would use this installer now it's getting local not a network path we don't have a whole network at home where I am recording so we're gonna put a let's do the @ symbol and we'll say C colon slash temp slash releases now right the reason I said the @ symbol before my string is because these slashes right here if I didn't have this @ symbol he's gonna treat these symbols as escape characters and so I'd have to create my path like this and that I think is just ugly and I also can't copy and paste it in put and explore so create like this like I want to input the @ symbol in front of it then the @ symbol simply says everything inside here is just part of the string it's not there's no escape characters now just so you know if you ever put the dollar sign there as well you still can put the curly braces and put code inside of curly braces so it's not ignoring everything that string that's ignoring those escape characters all right so let's close out our paren again this is hard code this is not the ideal solution here this is kind of version 1 or beta version we're just trying things out and that's why we're putting it on my temp folder eventually that's a network path or a web URL in fact the documentation even has a demonstration of how to use github to host your updates and then point this right to github so there's some really cool stuff you can do that we're gonna do the simple route for today inside here I'm really simple a wait manager dot update app that's it okay so it's going to update the app and just a wait for that before it closes out so that's all there is to checking for updates now you can put this code anywhere you want for example you could have a button click you could call this as well and have it be you know an update button or something like that check for updates but really we want this to be transparent to the user we don't want them thinking about it think about Google Chrome when you use Chrome you don't really realize it's updating it kind of happens the only time you you really know that chrome is updating or has up it is either that's a major feature change or if you leave chrome over for a really long time it starts telling you hey you know what it'd be great if you could reboot me so that I could you know install the new version so those are the only times you really see chrome update other than that kind of updates behind the scenes and then every time you launch chrome again it's a newer version same thing here it's going to just run behind scenes and when you open the application it's gonna check for an update if there is it will download the update but not do anything else and then when you close this application and relaunch it it will launch the new version so it's really just bhai essenes seamless and quiet all right now you have that done the next thing you need to do is when you go over to our properties and look at the assembly info now this is not something you probably know I poke around in but in here it's a bunch of things including for example your the title your assembly and all the rest you can also get to this by going to the properties themselves and filling out most as information so we're going to do is we're gonna change the Assembly version I prefer a stay with a one point 0.0 instead of the final point over zh in the provision version so let's stay right there with this Assembly version let's start with ok so this is the version number of our application so now if we switch over to release mode where he hit the build button make sure it builds it does and just to kind of prove it does we can come over to if you right-click on your winform project and go to open folder and file explorer let's go ahead and bring it over here we can go to the bin folder and look at the release and there you go there's all of our our build files including our win formed exe application ok now it starts off with a blank list of people so we add a person refresh the list Tim quarry is there and if we were to restart this Tim quarry is still there so starts out the blank database that's just one of the things that we set up originally so no problems there now that database will still have Tim quarry until we delete the database and start over that's not something to worry about for his application that's it I can just installer kind of point that out okay so now we know that's working when you do is create a new get package now you may know you get hopefully you are new kit is how we got squirrel in the first place we right clicked on references and said edge NuGet packages and so when you create our own new get package and this is what Squirrel uses for updates now nucleophiles are actually pretty easy create and we would have I will have a separate video on creating your own nougat packages but this is not really to that level yet this is just for this little application for the updates and so it gets used a little differently so let me show you how to create a new get packaged so I show you this right here in the Microsoft Store this is where I am right now there's NuGet package Explorer I believe you can also download it not in the store but this is pretty easy to get NuGet package Explorer pretty easy to use we'll go ahead and launch this and when it does it comes up like this this is a pretty simple little application to use we're a create a new new get package so let's say new package and this is our package when you start off pretty simple so let's start off with editing it so I'll click this icon right here to edit let's go ahead and zoom in a bit so I'll go to control and my mouse wheel to kind of make it a little larger just so that we can see it a little better there we go hopefully that's readable all right so the first thing is our ID visit the name of our application we can't put spaces here so we're gonna call this instead of these let's call it sequel Lite demo just to be consistent even though it's not really a demo we're deploying is a demo okay and the version is still is 1.0 0.0 and the author can fill it if you want I'm sorry of title whoops there we go there's the author the title is optional if we want to put a title or not so let's just call this the sequel light deployment demo okay again you don't need to have that you just need to have id version and author there are no dependencies we want to have so we'll leave that blank let's modify a description which right now it just says my package description so it's called this the sequel sequel light demo application to demin used to demonstrate deployment technology okay we're good there and that's it so now you can hit the green check mark save this and now let's start adding some package contents so the first thing to do I'm gonna drag us over here as you can see it let's see if I can't you get both on the screen at the same time all right now we have both these on a screen the first thing I do before I drag files over and like right-click on this package contents and say add folder or I call it Lib and then right-click on Lib I'm gonna say add folder gonna call it net 4 or 5 these are important Fuller's to have okay so these two folders are the foundation we're going to store everything inside of so this is wise the squirrel expects from us okay so now we can go into our winform UI folder so our solution then winform UI then inside bin release and that's important release then in here where I grab everything well almost everything and I grab the whole thing highlight the whole thing but then come through and I remove any files that say PDB so I'm holding ctrl key and unselect them let's go through and it's look and remove any PDB files that we find okay there we go now the PDB is is used for debugging your application we don't want that in our installer we don't keep those separate because I they could provide some source code to the end to a user that allows us them to reverse-engineer a little easier and really to debug our application not something want the end user doing so let's keep those away from the end user but otherwise everything in the release folder I'm gonna simply click and drag over into the net 4/5 folder there we go we have now created our full nougat file so that's everything we need we have both our package metadata which is our ID our version our title author description no dependencies and then over here actual contents which essentially just going to zip this whole thing up and it's gonna put create a folder called Lib inside there not net 4/5 folder inside there it's going to have all these files including winform UI exe okay and that'll be our executable so let's save this and the the general rule of thumb here where to save this is let's put it right in our let's go here to where our location is and inside of where a solution is essentially which is this root folder here called deploy demo really want to change that that's okay so we're gonna save it right here and the name it gives us is sequel Lite demo dot 1.0.0 up kick so that's the new get package file that's the extension and it's giving us a version number of 1.0 point out we want to keep that that way when we go the next version we can just increment this right here that will be obvious which version each of these packages is so with hit save honest so now it's saved in the location where our project is there is right there know as is about one megabyte that's because it has all those files inside of it now I'm gonna drag these off a screen temporarily just so that we can be over here but we're gonna come back to those in just a minute but instead we're gonna go to the package management console now if you don't have this package management consoles when your options down here no problem it is available by going to the view and then going to other windows and then in here is the package management console and it's right there so package management console okay so when I open this up and we need to run a command line prompt or command in order to get this Rea for release so we started squirrel let's actually see if we can't there we go so he started squirrel and we do a space and then two dashes and say release if Phi okay release a Phi and then we have our our name so sequel light demo dot 1.0 point oh god nut cake okay we make sure that's the right one so let's go over here and just make sure so sequel Lite demo dot 1.0 0.0 dot and u PK G so there we go so there's our release of fire getting a tray for release okay we hit enter we wait for it and should be done and it is let me come back over here now notice is one extra folder it's called releases you open this up we now have set up the Exe ms:i and our full NuGet package file all right so that's that's really it we've now created our release package and in fact we want to do is when I run this setup that Exe now yeah we're going to and then from there we'll be able to see our file install run it and then do our updates all right so I'm gonna do minimize this and we have just my desktop here now this is now my primary desktop I have a secondary desktop that I do my recording on just because it's cleaner this way so when I run this execute one let's go ahead and copy this out and I paste it right here now it's going to install it probably to my primary desktop but we'll see and if so grant dragged across but this is the whole process for installing my application now now this is where you install it on your your eventual machine ok now before we do this one last thing I almost forgot I wanna grab these these files I copied them and I'm going to go to let's actually open a new window there we go and in here I have as release as folded this is where I said see tamper leases this is where I said the updates would be I'll paste that in here this is standing in as my network location or my web server that's serving these files okay this is where this would be okay so this is the location where it's gonna get the updates from so now the user just runs the setup.exe in fact let's go ahead and run this I'll just open it wait just like it and let install thank you much oh sorry done sorry I missed it it's that fast okay so now if we were to that's the icon to install a desktop notice it's really ugly that's okay we can update it in the future but if you run this it should run our full application and we have a problem so I looked at this real quick guys pause the video and looked at because it should be launching right now in fact it is launching right now it's just that it's crashing then so we have a bug her first application which is awesome but instead of you know going back and showing you the real way and you know not showing you any problems or errors I decided instead I'm going to do them and show you a real-life problem ok so this is a problem right out of gate in that it won't launch if I open up a Event Viewer it says it crashed because it can't find a sequel Lite file so this as well as but not bugs this one most things with sequel Lite that we have to work with and that is if we go to let's pull over here this is the wind form product in fact here's the the solution go wind form UI bin release we have the x64 and x86 folders inside there is the sequel Lite Interop dot DLL that's very important so it was saying I can't find that Interop DLL I'm thinking well it should be there so let's open up our sequel Lite demo 1.0 and look it there's nothing inside those folders when I clicked and dragged them over brought a folder but not the thing is below the folder so it's a good learning experience so let's grab a 64-bit DLL and we'll put that in that folder and we'll go to the x86 and put it in the x86 folder and that should solve that problem so what do you do now well you hit save and you close out this package I'll bring this over and we're going to do is this releases folder which this is actually here the desktop you can go ahead and delete this and I'm going to do it it'll probably off screen but that's okay I'm going to install the the application so it's called sequel Lite demo and in fact let's draw out drag over here there you go so there is the sequel Lite deployment demo I see I install ironically it does give you a UAC prompt for uninstalling when it didn't for installing that's all there is to it the icon goes away and everything is off the disk now so now let's go back to our application and in here couple things we need to do first of all before we go there let's go to our our temp folder so let's grab this and then inside of releases let's go ahead and delete everything there I'll pull that off and now that we're done all this we can go ahead and release if I the same exact version I've saved the updated nutcake file go ahead and release if I the exact same version it should go ahead and create that for us now let's just verify it did that go to releases and there we go so there's our new files they have been updated as of just a minute ago so I will copy all of these I'm gonna go to the temp folder where they live let's bring that over here and we'll paste that in this is where all the updates come in as well so this is where you can run the update from so let's go ahead and minimize all of this and try this all again I'll go ahead and launch these setup data exe file so launching septic exe and right away it launches it's already done now that incredible now let's drag that icon over here so you can see as well there's the icon this is the 1.0 0.0 version of our application notice it has Tim quarry in the list that's because it grabbed that file in the release folder so we really should have kept it as an empty file or redone the file so that it was empty but that's ok it's not you know the end of the world especially not for this demo but it does work so Jane Smith we can add refresh now Jane is in the list as well ok so we're good to go now let's change some code so let's go over here I'm going to unpin that I'm gonna shrink back down to a more reasonable size for our font because that was just crazy big for our our font on the form itself now let's make a couple of tweaks first so I want to see that version number up here so in the the code behind let's go ahead and add a method called private void and version number and I'm just gonna do is gonna add a version number to ever text we already have in the the text of the form so the people form dot text which is this right here we're going to add some new text now getting the version number is actually a little more complicated than just saying get me version number so let's start with system dot reflection dot assembly let's call it assembly equals system that reflection that assembly dot get executing assembly and then the file version info so that's using system Diagnostics so file version info and let us call this verse info equals file version info dot gets version info for assembly dot location okay so that's gimme the assembly information for us so they don't have all we need and now I can say is people form dot text things dot text let's look real quick so the people form the property for that should be that text all right so it's the up that's why this not people form this so this dot text plus equals we're add to the end and we'll say space that's where a dollar sign first say space V and then let's do a V dot and then the version number so to our curly brace and then say version info dot file version ok and then we can put a semicolon at the end of that and that should add our version number on let's just make sure it does we're in release mode that's okay it's gonna yell at us and say hey do you wanna you know stop debugging let's continue to bugging for now so there we go sequel Lite demo form by Tim quarry version 1.0 point out perfect we've got a new version there so now let's call that good so how do we do an update so first I'm going to do is after you've updated our code make sure you're in release mode now normally when you're working on an application debugging it you want be in debug mode the difference here is debug mode is designed for you to be debugging and so you can do things like look back at old variables when you're in release mode it acts much more like it would in production and so things like garbage collection happens right away and so you might lose what variables are you know what the data wasn't the variables if those variables are out of scope now so debug is definitely the way to go normally but once you are ready to deploy change over to release mode next go to your properties know about that assembly info GS come down and change your version number now how you change your version number it's up to you you could do it based upon well every time I make a change I modify this last number here and then these are minor changes you know minor overall changes and this is a major change that's kind of typical but it's up to you how you do it you could say you know what this is already 2.0 because it's a such a massive change it's up to you but make your change and go ahead and hit save okay and then you know you wanna make sure that you do a build build solution okay that's important okay so the next step once you've done a build on this is to come back over to your package explorer open up your your package or NuGet package go to edit change the version number here okay it's very important change the version number and hit the check mark then open up this right here I really want to do is let's go over and open up this folder and file explorer and minimize this and now you're gonna find all the files that have changed in the release folder so now we know the only files really changed is our wind form DX II and just to be on a safe side it hasn't changed but just gonna save side will change will grab the config file as well so click on those drag them over here oops I put in the wrong level so you know drag them let's here right either do this delete and we'll delete one more time and then find the folder itself so hover over net for five and release NSA do you want replace and you say yes and yes and that's all the files we need to update if we had made changes to our class library we'd need to grab that dll as well okay so you can just look by the modified date and see which ones have been modified typically it's just the exe and any dll's that are associated with what you have created not for example the the squirrel dll or any of your nougat package DLS so you dragged us over we'll close that out and now you do don't hit save do file save as say the same location but notice the because we changed a version number and this is great it actually changed our file name we did save as and so you see it safe and same as a new version number one point 0.1 we can now close that out we can open back up our sequel Lite and open up our package management console let's go ahead and make it a little larger again and we have this release if I already here for our version 1.0 but now let's go ahead and change this to 1.0 point one and hit enter and once that completes we can go ahead and zoom back out a little bit more here and we can look at that folder and look at our releases notice now that there is a 1.0 full package a 1.0 point one full in a 1.0 point one Delta in set Delta notice that the file size we can see that it's only 12 kilobytes the full package is two megabytes over two megabytes but the the Delta is just that difference which is 12 kilobytes there's something really small so now we can take these new files which we just copy the whole thing but it's up to you if you want to copy the whole thing or not and then we'll go over to that folder that we store them in C temp now let's paste and overwrite everything so now there's this is again this is the simulating the network location or the the web location where central location where our updates are located and that's really it now if we run this application notice it does not say a version number here there's no version number at all so you're thinking when's it gonna update it's not close it out start it again version 1.0 point one in the background when we first launched the application it download the new version but waited until you restart our application when we did it gave us the new version of our application so that's really it you have that set up to exe file you have the location where you have all your new get packages for your deltas and your full versions and then you just run your application and it updates as needed so this is how you can make really rapid updates to your application and deploy them with very very little work now yes there are steps to mate the steps include first of all modify your application making a change change in the release mode and building making sure you change your assembly version to a new version cream you know going to your new get package opening it up making the change to the version and then put in the new code or new files in your net 4/5 folder and then doing the release of Phi and then copying those files over to your network location yes that's a lot of steps but where and there was it complicated it's not it's always predictable what you have to do and so this is where is where I challenge you to do next in your your progression of learning this is once kind of get a handle on this and understand what's happening the next step is to automate this because this sheep just part of a build process so that when you make your changes and you say you know what yes we're ready to release then he would change your assembly version and then let your build process a Oh as a new version make the new package put the new files in it change the version number run run the release a fight move those release of five files into the network location and you're good to go so really what should happen is once you have this build process down it should be a matter of just a small lil change changing your your version number to the right version and then everything else just happens okay so that's that's the end goal but for now this process is pretty straightforward okay there's not a whole lot here that's complicated there's not a whole lot here that the cause of you issues it just kind of works okay so hopefully this kind of showed you how you can very easily deploy your application to another machine and keep it updated without a whole lot of work on your part this does work a lot like modern applications like for example in Google Chrome where it installs per user so it can get around the idea of having those UAC prompts the the promises you know do you want elevate your security in order to install this so it doesn't install for every person on the machine if you want to there's ways of doing that but for the most part the focus of this installer is getting your application onto another machine get it running with as little prompts as little interaction as possible just get to work and so one of the things that people often ask for is well can I have prompts can I app you know it can I say where's we installed all this kind of stuff and the answer is no the most part this is what it is it just does one thing well so he wants more advanced stuff this might not be a solution for you but for most cases this just works it's very quick it's very easy to do and it brings you to that next level in your application deployment now I was gonna show you how to make it automatically refresh I think you'll lead that for you so take the the finish source code from this video and download it and see if you can't get to first of all install the way it is and then take you to the next level by adding another version number with the updated code and make sure that it works for you okay so I hope you've enjoyed the video if you have any questions or comments please leave them down in the comments below I'll try and get to as soon as possible alright thank you for watching and as always I am Tim quarry [Music] you [Music]
Info
Channel: IAmTimCorey
Views: 69,684
Rating: undefined out of 5
Keywords: .net, C#, Visual Studio, code, programming, tutorial, training, how to, tim corey, C# training, C# tutorial, installer, c# installer, desktop installer, clickonce, click once, c# click once, msi, create msi file, c# deploy desktop, c# squirrel, squirrel, .net squirrel, squirrel windows, c# updater, app updater, C# app updates, c# clickonce
Id: W8Qu4qMJyh4
Channel Id: undefined
Length: 47min 32sec (2852 seconds)
Published: Mon Oct 29 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.