.NET Core 3.0 Desktop Apps - Creating and Publishing WPF and WinForm Apps in .NET Core

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
dotnet core three promises to be a big update to how you build desktop applications in c-sharp with incomes upgrades to dotnet core for wind for maps and WPF apps in this video we're gonna look at how to build and package WPF apps in dotnet core 3 Neto we'll also look at dotnet framework to UPF applications just for comparison to see what's changed and finally we'll look at a win for map in dotnet core 300 although that'll be a little bit different now this video uses the preview 7 release of dotnet core 3 demo we're looking ahead at what will be not why you should be using today in production the UPF is now stable enough to demo but you'll notice that the wind for map is more difficult to work with since it does not yet have a visual designer kind of a drawback for that drag-and-drop wind form experience now the source code for today's video is available at then to download using the link below in the description you'll also find links there is sign up for my mailing list and for patreon now if you're a member of either these make sure you're checking your email this week for patreon members of the $10.00 per month level or higher you'll be receiving that application idea PDF shortly also I'll be releasing my office to a video on patreon this week to members at all levels I actually just record it about 10 minutes ago now for mailing list members don't forget that the Christmas in July sale ends this week as the end of July so make sure get those deals while I last alright so let's get started so I had a Visual Studio open here this is Visual Studio 2019 let's create a new project and we're gonna do a dotnet core and I filtered already C sharp windows desktop so that's why it's filtered to this list and I have WPF app dot net core now if you don't have the preview bits for dotnet core 3 - oh you won't see this option you have to run the preview version of Visual Studio 20 and have updated it recently we have dotnet core 300 preview 7 came out just a few days ago so notice the preview in the upper right hand corner here and now it says WPF app dotnet core now if you don't want to use the preview bits if you're just looking for what's coming that's fine but this will be out in theory around September so the release to manufacturing the RTM version the version that is generally available is going to be it's going to be in September there's gonna be a version that is ready to release but it's kind of their their their final version the one that they're anticipating to be released but they want to have you know make sure there's no more bugs or some like that they'll be done hopefully in July or early August so is seeing how its July 28th right now it'll probably early August before that comes out but then I'll be the the last versions ready now with that being said I have not yet seen a visual editor for wind forms so I'm wondering if we're gonna push off dotnet core 3.0 is release or if may wind farms won't be a part of it and maybe a 3.1 or something of that nature not sure yet this is all tentative timelines based upon what we've seen so far so with that being said WPF app dotnet core now we're I call this let's see let's call this the DPF core is a product name and for the solution name is core three demos let's call it that I'm not gonna put dot in there I'm not gonna put spaces my hope you know I'm trying to avoid all those special characters I just want numbers and letters so therefore core three demos all right so let's first need a dotnet core 3.0 WPF app ocation so once this cos create there we go it's gonna look a lot like your typical WPF application you have your designer you have your zamel you have code that looks like code and you had a code behind for your jpf as actually that's it over there it looks just like normal c-sharp code and that's really beauty of dotnet course 3 2 or net core in general you know people often ask well you know it's all that dotnet framework stuff outdated and the answer is no because you almost can't tell if you're in dotnet core or dotnet framework because a c-sharp looks almost identical there may be a slight difference here or there for example we don't have an app config here but the most part is identical so let's actually create railway our da PDF application for dotnet framework so we can see the differences so right click in solution and say add new project WPF app for dotnet framework we hit next and we call this WPF framework so there's two F's there the APF and then another f4 framework we create and I'm doing a dotnet framework for dot 7.2 I create a net and now we have basically the same thing I mean if you look the big difference is that we compare the WPF core versus the API framework we see that we have dependencies first or here we have properties and references and then we have app sam'l and then we skip app config we have app dot sam'l let's compare these two so let's do this let's close everything out let's open up this is the core on the left and it will open up app sam'l the full framework on the right and let's make sure I get this right I did so I've changed this visual studio so that when I click on a file it highlights it over here on the right let's notice this is the full framework version and the left over here is the core version notice the differences or lack thereof they look pretty much identical so there's not big changes in how the app zamel works so let's look at the main window and open that on the left and the right the same thing on the right it's gonna be the full framework on the left it's going to be the sam'l I'm sorry the dotnet core and again it's the same I mean word for word the same let's try again with the code behind so view code here and then view code here and again you can't tell the differences they're the same thing and that's kind of why the first thing I want to highlight is the fact that if you're used to working with WPF in full framework you're used to working in dotnet core version of WPF they're the same thing the big differences are you don't have app config so this app tie config will restore things like our connection strings you don't have that in dotnet core you also don't have the same way of dealing with references so reference is over here we have this references over here we have dependencies and from there we can see the dependencies we have on here we could also right-click and still say majnu get packages so it's very very similar and you can get the same things done but is just a little bit of difference now coming back to app config this is one where you'll probably need an app duct configure something similar and that's where you'd have your app settings JSON file and that's that's restoring important information like connection strings now things that dotnet core is helping us do is remember that maybe it's not the best idea at a story connection string in a text file instead may should put that into key vault which is on Azure or some other secure way of of storing that connection string so that you're not storing passwords in clear-text when they shouldn't be now just to be again clear on this side with desktop applications you're going to need a store that password in a way that the user could get access to it because at the very least they running the application on their desktop and even if you encrypt it in every way possible they pretty much still have access to that connection string if they are motivated enough so still don't give them access that they shouldn't have in that connection string and that's where you know if you watch my video on connecting c-sharp - sequel or sequel a c-sharp I talked about the idea of making sure that connection string is only limited to just what you want the user to have access to that's a whole nother rabbit trail but I'll make sure to point that out that with these desktop applications you're gonna have to have a connection string somewhere that the user has access to even with encrypted because they on one side encryption so they can still get access to that somehow okay so with that being said if we we're gonna go our this application here let's close out the uh let's close out everything else but Oh rats get too fast and close out everything but I'm gonna do is I'm gonna do something I tell you not to do um and I'll show you why but also it's a quick and easy way I just create something on that form so if I had a button I drag and drop it onto the design window and it puts a button here I take nothing do this because this kind of defeats the purpose of and I also broke it there we go this defeats the purpose of TPF a lot of the the benefits you get from DPF and the HTML like way it lays things out because notice it's just on here and it says here's the margin and then it says here is the height and here's the width and these are all fixed numbers they cannot grow and shrink as needed isn't he fixed to the size no matter what that's not how DPF was designed to work but that's where you get me a drag and drop so your drag and drop I always encourage you take the margin off take the height and the width off and then you'll have a button that is designed it's got all the text in that you need and you can you know play around how it's set up by the same time it's not fixed in one specific position then you can put it in your grid in a more designed way with that being said I'm just going to put it here and say hello world something like that isn't anything work we're not going to this is not about making a DPF application because the APF works the same way here as it does in full framework in fact one of the questions you may have is if you see my other DPF videos where I talk about caliber and micro and doing mvvm framework I use calibre micro a lot because calibre and micro for me is a way to make mvvm much easier to implement some people have asked why don't you use just you know straight up the PF and do your own mvvm and the reason why is because it's kind of like reinventing the wheel every time and I don't want to reinvent the wheel every time I want to have somebody else having done the hard work and I just build on top of them so that's why I use calibre micro so the question may be well can I use calibre and micro well if you were right-clicking dependencies in our core app and say manage NuGet packages and go to browse we can look for calibre and micro first result is caliber and micro and right down here it says dependencies are core and this will work in this version or should so we install this and it should work in our dotnet core just as it is now it does say that it's targeting the dotnet framework instead of the dotnet core so with that being said we could still use it but there he is getting some corks possibly with how it works and how it compiles now this is not the end of the world because even though it it points a.net framework we can I believe still use it in dotnet core and we can target that but also and that's let's be very clear on this just because WPF has dotnet core behind it does not mean it will run on anything besides Windows the clues in the name WP f stands for Windows presentation framework or foundation favorite thing anyways it's one of those two F's but it's windows that's a dahlias stands for word windows it will only work on windows and that there's a whole series of reasons why but basically it's based upon Direct X which is a Windows only thing and some other things as well so you're not going to get cross-platform compatibility with a WPF dotnet core app so the next question that may come up is well then Tim why would I ever move to.net core form I tell you PF application when dotnet framework works just fine and the answer is yes it does work just fine however dotnet framework is done as a four point eight and what I've done is not that's over life is not over for dotnet framework in fact it's got a very very long life span ahead of it it just won't beginning any new updates except for security fixes so 4.8 is the last feature update version of the.net framework that's why the next major version after dotnet core 3.1 or something like that the next major version though it's gonna be dotnet 5 which is gonna bring in dotnet core and I believe Samer and the other things as well and kind of combine them under one umbrella in one language and one framework and it's looking dotnet as dotnet 5 because the last dotnet framework version was 4.8 so with all that kind of backstory the reason why we're moving I think we reason why Microsoft is moving over to dotnet core for the the backer of DF is because it's the language that will continually update dotnet framework stuff is a mature language it's got a lot of stuff in it and you probably could do just fine working for the next 10 years or so in dotnet framework however we want all the shiny new goodness for our desktop applications that's where dotnet core comes in also here's a really big addendum to that is that dotnet framework is slow in comparison to dotnet core dotnet core is much much faster and the reason for that if you think about it becomes a little obvious dotnet framework has come since 2001 to them to time frame and so for the past you know 17 18 years or so it has supported all those changes and the lots happened in 18 years of software development and so there's a lot of legacy stuff inside app framework now I've cleaned some of it out but with dotnet core they went back to the drawing board and reimagined how these things should work and work better and so dotnet core is much much faster and so just moving your application which probably about 95 to 98% of it if you have an existing application most of it will go over to dotnet core without a problem so just by doing that you will see a speed increase in your application a pretty significant one depending how you use different parts of the framework or the Ornette so there's definitely a huge benefit to moving over and as you can see the differences are minor so I would definitely encourage you to do that now let's talk about how do we get this application deployed now if you were to let's just build the solution here from it and once we do that let's look at well do the dotnet framework version we'll open this folder and File Explorer will bring it up and look at our bin-debug folder and we have this exe which that's the actual application and then a config file which is our app config file pretty simple stuff if we do a same thing a dotnet core and go to our bin folder debug we get dotnet core app 3.0 and here's all a dll's now we do have the calibre micro dll's but then we have the core DLL we have the exe and we have some JSON files which that's a runtime config and some dependencies and all the rest how do you actually deploy this well let's do this let's delete the actually can't delete right now no problem let's just close this out what we're gonna do is we're gonna set this to a PF core app up for deployment now first we get rid of that new you package just make sure doesn't cause any problems for me if we don't need it there we go loading loading well should we get clean and we will wait to build it so this this is a really simple nothing extra simple application okay it's just one form with one button if we run this application which we can I'll show you it's gonna pop up and it's gonna look like this and notice again that button won't move really and move set aside but not top to bottom I can cover up but it hasn't do anything but that's our hello world button okay so how do you package is up well if we click on the do PF core application it's going to pop up the CS proj file now this is something new that you can't do a dotnet framework projects notice I click on here nothing changes I can't edit this project type while it's loaded you actually used to have to unload your project and then make the edits now we've got net core applications you can actually click on them and make the ads right away so that's really helpful you can do this live we have to make some edits here in order to get this to work the way they want and the reason why I could I'm gonna want through the end goal here is I want to deploy an executable file an exe file that has everything I need inside of it so and that includes dotnet core I want to deploy everything is 1 X cubed file no dll's no extra stuff just one exe I can give to somebody a thumb drive and say hey run this as my complete application they don't have to have anything installed on their Windows machine they could have you know an older version of the.net core they have no dotnet core can't have no dotnet framework doesn't matter my exe will run how do that that's our end goal but first let's right-click and say publish we're gonna publish to a folder this path is fine let's remember though being slash release slash net core 300 slash publish cool let's create the polish profiles all right edit it and say sounds good runtime our tyrunt is portable let's change it to a 64-bit target and we're gonna say let's do framework dependent first meaning you have to have dotnet core 3.0 installed on the machine let's save that and we're gonna publish this it'll take a little bit because it's me the first time especially a little bit slow but well that's there already so that was quick so let's right click and open folder in File Explorer bin release dotnet core 3 publish and here is our de PF core DFC which is a hundred fifty seven kilobytes we have a de PF core DLL we'll just six kilobytes and then we have our JSON and PDB and our JSON file the only files really need to run this application of these two right here and if we double click this then we get our application like so so it works however I have dotnet core 3 install in machine you might not have that somewhere else so let's redo this let's go back out of here and we'll delete the release folder and where I try it again let's move this off the screen for now alright make this edit and say well we want to be self-contained meaning bring that whole dotnet framework or down at core with you and package it up as part of our application that's it save and we hit publish and what this will do is it will it'll bring evident needs to run our application and put it in the file with us so release dotnet core 3 publish notice all the stuff that comes with it this is all the files with our application including the APF kori XE and it's still 157 kilobytes we also have our de PF core DLL which is six kilobytes so what's changed well all this other stuff these are all the things if you look we go down here system dot core system that console system that configuration these sound familiar system not data that's because these are Microsoft dll's this is what is in either done that framework or dotnet core depan which when you're using this this case it's the dotnet core stuff so that's all Microsoft stuff so instead how you install the the.net core 3.0 preview seven version on a target machine you could just copy this entire publish folder and paste it somewhere and then have the user run DPF Cordy I see now this sound it's looks overwhelming but the reality is we're used to this I don't advocate our computers if you go to your program files and look at let's say office there's a ton of dll's there's a ton of files we don't look at those we keep them all on our Program Files folder and we just have a shortcut to word exe or Excel you ex exe well in this case you do the same thing you go folder and have a shortcut to do PF quarry XE dad work however if you're looking to give this to a user and have them just run themselves this is confusing they're gonna ask you which file to execute obviously it's giving a lot of different choices that's not the great idea so let's go back to our bin folder and delete I'll release again and this time I come back to that CS proj file the DPF core CS proj file we're add a few options here so inside of Property Group we have three options to first of all is runtime identifier notice the intellisense pretty cool pretty cool so wind dot x64 how do I know the best of value to put in here well if we come over here to our publish window you go to edit win - x64 my other options are wind - x86 for a 32-bit application this ones currently is a 64-bit application I like you an armed application or OSX and Linux different versions I can't compile a DPF application for Linux since it won't run Linux so I've added that runtime identifier the second thing we to add is publish single file now this is not in intellisense so publish I make sure I get spelled right publish single file and true and then also publish trimmed and the reason these are not in intellisense and it's also true is because these are brand-new they're just recently added to dotnet core 3.0 I believe they were first add the publish trimmed I believe is first add in preview 6 and I'm a crayon preview 7 so it's been recently but publish single file is true and then publish trimmed is true so what single file does is it says I want everything in one Exe so dotnet core 3.0 preview 7 include that with the executable with all its dll's but then publish trimmed says we really don't want to have the entire dotnet core 3 in our exe because that seems wasteful because I'm not using certain parts of dotnet core 3.0 for example I have you in touch system data so there's no reason to put system data in to my application so publish trimmed what's gonna do is gonna read my application it's gonna see what parts of dotnet core it uses and that's gonna put just those parts into my executable so let's save this and now let's publish again notice I still have self-contained x64 all the rest however because I saw those settings up and I hit publish it's going to first of all say build failed excellent this is preview bits let's look at my output just make sure that my error list sorry all right it's complaining about my my obj folder which R is a full we can get rid of I'm gonna do is delete that folder entirely because it'll recreate it I think that might solve my problem then restore a files start a publish and it looks like it's going to work this time this will take a little longer and the reason why is it's going through and scanning my application seeing what's what needs and creating that file for me so this is a little longer but the result is going to an executable file that we can deploy to our app our users so bin release net core 300 publish and there you go just one file the PDB is used for debugging you don't have to any price shouldn't give that to users so just our exe now if you notice the file size it used to be a hundred and fifty seven kilobytes now not sure you can see that or not but it's 91 megabytes that's a significant difference however like I said that has all of dotnet core 3.0 preview seven embed in it so you can run this application it will run just like it would normally and the result is you can run it on any computer any computer that has windows on it either doesn't have dotnet core on it so that is the the the full compressed single file deployable Exe for your DPF application so that's something new with dotnet core 3.0 is this single file trimmed file that you can deploy with dotnet core baked right into it alright so that is the APF we can deploy that using that file or using that whole set of files or not decided to do a framework dependant instead if we do framework depent then we expect to have dotnet core already installed me on a machine and then it just does the the exe in the dll and you can copy those over okay so that's how we can publish our file now obviously we wouldn't want to do a right click publish every time we want to have something to build process in place and nothing we've done but this shows you at least how to do that also I probably still at on top of this squirrel or or some other way of packaging into an MSI file of some type for deployment they can have it installed and uninstalled as well but it's really convenient just to copy this exe over somewhere and paste on a desktop it have a user right so that's a great alpha version beta version that you can just give somebody and not have to do a lot of work around compiling and building and deploying and packaging and all the rest for your application to give it at somebody so just think about but that's the PF core versus framework framework he cannot do that the same way the publishing is is a bit different I can get a little messy it's just not quite the same thing so this is more of the if we wanted to do the drama blank here but click ones application that's where timeout you can do that like that but this is has a lot more options to it with our jpf core okay so that's de PF core like I said sam'l pretty much the same stuff you can still do you know anything you want in your your sam'l like normal it has the the drop down menu you can see we can and if you want here data grid all the rest so it's just the same okay so let's talk about WinForms now that I promptly get into wind forms let's add a wind form products a wind form core project so if we go we searched for form and notes a filter on still a c-sharp windows desktop so I say forms and I get dotnet framework and dotnet core they do a dotnet core I'm gonna say win form core it create and it's a little different okay it opens up this right here which is this is the code behind for our format school and it says form one cool so I don't click on it and I get this and this is typically the screen we see it we don't you don't care if you don't read this but typically this is when we delete a an event handler when we haven't deleted it from the front we get something like this that's not this is instead what it is is the designers not there they don't have a visual designer yet for Windows forms for dotnet core it's coming and there are some workarounds and I debated if I show you a workaround or not I aside not to and the reason why is not really wanted to pry view the information or I don't think you should do it if you have the need right now to design a dotnet Corwin form application then yes or some workarounds give them a shot but in the next cold months will have products month or so will have a visual designer for when so it's not really need I don't think to learn those workarounds unless you do it right now but we that said if he said that's a start-up project and we hit go we get a winning form application so there's a standard way we learn about win form application we can still write code against it we can still if we go to the designer the CS file we could modify this to actually change things in here add things manually put them position them where they should go using the coordinate system it's ugly and no wants to do it that way because that makes wind forms ridiculously hard and one of the benefits of wind forms it was designed for drag and drop where DPF really wasn't so you you lose that benefit so you lose a lot the reason why you use wind forms so that being said they are in place and dotnet core three for right now I would encourage if you're gonna do win form development I would say maybe hold off on new development but if you wanted to upgrade an application from dotnet framework to dotnet Cora try it out that would work just fine wind forms so you can still do that you can still run the application and in fact I'll have a video on that shortly on how to upgrade a wind form or de PF application over to dotnet core from net framework that's ain't coming now I'm debating even taking my my c-sharp application from start to finish course where I build a wind form application with some pretty complicated stuff in a background for logic and did access I'm thinking about moving that over as well to dotnet core and doing a course on that just to see more of a real world larger application being ported over you can see that and also of course timko retail manager that's one of the big things behind that was we're building it as a dotnet framework application intentionally so that we can have that porting experience or the.net core because in the workplace today most applications that are currently in existence are dotnet framework therefore there's giving a large period of time where there's gonna be a need for the skill in transferring from dotnet framework or RedNet core so I try and make sure that you have the skills and tools necessary to make that transition as easy and painless as probable as possible okay so that's what we get with wind forms it's not really there yet it's not really ready yet the code is the code works just fine is just the designer that's missing now I haven't touched on the other desktop based application which is the console application because console has been running for a while it's been dotnet core of goodness Miami dotnet core one that Oh got the console up not positive in that one but it's been around for a while because consoles work across platform so a console application will work on Windows on Mac and on Linux and pretty much do the same thing as well they have really changed how they operate is just that now they work cross-platform and I've already covered before so I'm gonna bring them into this video this is more about the the new dotnet core 3 type of stuff so I have a question for you once you leave and the answer down in comments but what are you looking forward to what what things about dotnet core 3 io of sparked your interest maybe it's not even about the the desktop application but its but something else that's that's happy and 300 there's some some nice big tweaks in there we're moving away from Newton softs JSON to built in JSON parsers so that's not a big thing that's happening but what what we're looking forward to one of the things that you would like to see me cover that I haven't yet in the.net Core 3.0 space or even dotnet core in general we doing some more dotnet core website building without building with razor pages in MVC as well as playing around with the class libraries and create with us as well as you know this channel is all based upon your feedback so anything give me as far as what you wanna see I put that a list as more people say it I bump it up the priority and here's the way I think about things if you say something that probably means that there's 30 or 40 people out there or more that are also thinking it so for every person that thinks that I multiply that by a large number so your voice makes a big impact than what happens okay so as last stuff coming on a pike but I'd be interested in hearing what you would like to see next especially in the.net core area okay thanks for watching I like it's the source code for this what there is the source code is in the link down the description go ahead and click on that if you want that and also if you have already she ate a like this video and also make sure you're subscribed to this channel so you can get alerted every time I release a new video Mondays and Thursdays of the schedule right now okay thanks for watching as always I am Tim quarry [Music] you [Music]
Info
Channel: IAmTimCorey
Views: 97,247
Rating: undefined out of 5
Keywords: wpf .net core, wpf .net core 3, wpf .net core 3.0, wpf .net core 3 example, wpf .net core designer, .net core 3, .net core 3.0, tim corey, iamtimcorey, wpf, wpf desktop application, wpf desktop application sample, publish wpf application, publish wpf application visual studio 2019, wpf publish exe, self-contained wpf, self-contained .net core, .net core self contained app
Id: uc3tC6_mEvk
Channel Id: undefined
Length: 40min 44sec (2444 seconds)
Published: Mon Jul 29 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.