Publishing - WPF MVVM TUTORIAL #10

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
alrighty we have covered what i believe are the core concepts of wpf mvvm applications we have a fully functioning application now we're just ready to publish it which is arguably the most important part so before doing the publishing what i did was just polish up the application so for example added a few things if we load these reservations and no reservations have been made we show a message for that for making a reservation got some more validation on here so if we have an empty username then we get a validation error another thing i added is if the end date is before the start date we had this validation last time but what i did was disable submitting if we have this validation error but then if all the validation is good we can submit and now i've added a loading spinner and disable these buttons while we're submitting so we still get the success message and then the reservation appears and then lastly also added an error message to this ui as well for example if we get a reservation conflict exception we get an error message for that so just wanted to make those improvements but i did them off camera because there weren't really any new concepts there it was kind of just building off things that we've already done and doing it in other places but now get ready it is time to publish and this is actually extremely easy and dotnetcore.net5 and beyond usingthe.netpublish command so if we go to our project and select open in terminal we get this terminal down here and we can do our.net publish so pretty straightforward all we have to do is dotnet publish we want to publish this in release mode so not debug so we can do a c release and let's do it all right success so that has been published to our bin let's go check that out all right so in the bin we published it as release our project is net 5 for windows and we have our publish directory and here we go looks good here is our application so let's go ahead and run it and there we go seems to be working well as we see our database did generate inside of our bin that's good we can make a reservation and there we go all good so one thing to note about the way that we publish this is that in order to run this application the user is gonna have to have dot net installed on their computer so in some cases that might be an issue but there's a way around that so on.net publish we have this option for dash dash self dash contained and that's going to publish our application as self contained meaning that the dotnet runtime is packaged up with the application so the user will not need to install net on their machine let's try this and everything should work right no it does not so if we want to specify self-contained we also need to specify a runtime identifier so if we go to our project file we can edit that and we need a runtime identifier you can also have runtime identify yours if you have multiple runtime identifiers but we're just going to have one and this is used to specify our target platform so if i bring up this runtime identifier catalog we get a list of all the different runtime identifiers so here's all the windows ones and linux and mac but wpf doesn't work on linux or mac so we don't worry about those we are just going to focus on the windows ones and for now we're just going to do win x 64. so our target platform is windows x64 machines and now we can do the dotnet publish again as self-contained and let's go check out our bin so previously we were looking in this publish directory and this had our exe in it but now our application has been published to win x64 so that's the runtime identifier that we specified let's go in there and as you can see there's a lot more in here now because we included the.net runtime with our application so if i scroll through here here we go we got reservim and we can run again generates the database that's good and now we can make our reservation again so everything works just fine except now the user does not need net installed on their machine oh and actually i was running from win x64 but inside this win x64 we should go into the publish directory and this is the actual publish output although honestly it seems to be pretty much the same so the last thing we can do is actually publish this as a single file so to do that do our regular publish except now we can do a p colon publish single file equals true and try this again alright i messed that up this should be a dash p publish single file try that again and seems to be working let's go check out our publish directory and maybe i should wipe this first so let's delete this do it again go to publish and here we go so not necessarily a single file but a lot less files so that's good let's try running this and there we go all good let's see what happens when we delete all this other stuff though so we want to leave the app settings.json since we read the connection string from there and we obviously want our database too but let's delete everything else and is this going to work all right definitely doesn't work so publish single file isn't necessarily a single file but it's a lot less files that's always good another thing i just noticed is that we never added an icon to our application so we can go ahead and do that real quick let's add a new folder in our project for resources so i add this icon here you can grab this from source control but it's a dot ico which is the required file type for wpf application icons but now we can just select that here save resources icon.ico select that and now we got a nice little hotel that's exciting so let's publish again so here we go our application was published and now our exe has this beautiful hotel icon it appears in the top left and we even get it in the taskbar looks like i still got a background on it probably to remove that but i am pretty satisfied with the results so lastly if you're interested in automating your.net publish with github action ci cd i have a video on that that i'll link to not going to get into that here but perhaps i'll publish this application and create a release on github in case you're interested in downloading it since i'm sure everyone is just so desperate to download reservam and manage hotel reservations how exciting anyways these are the core concepts of wpf mvvm applications you are now ready to venture out into the wild and apply these concepts to your own application feel free to use the source control as a reference be sure to stick around subscribe and check out my other videos for more advanced concepts interesting experiments and fun tutorials if you're enjoying the channel consider becoming a member other than that leave a like and subscribe for more and go chase your dreams
Info
Channel: SingletonSean
Views: 1,220
Rating: undefined out of 5
Keywords: wpf, programming, visual, studio, xaml, custom, control, generic, system, line, display, timer, template, binding, c#, how, to, series, tutorial, easy, time, maintain, package, design, part, event, code, framework, register, static, state, default, view, style, wrap, panel, stack, scroll, viewer, first, width, action, void, model, layout, user, box, mvvm, data, error, icon, class, relay, clean, simple, sub, log, file, host, grid, scope, margin, deploy, github, actions, release, download, essential, validation, rule, logic, story, navigation, store, publish, production
Id: I_Lj2_IkmtA
Channel Id: undefined
Length: 6min 23sec (383 seconds)
Published: Sat Nov 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.