.NET Conf 2019 (Day 1)
You. You. You. You. You. You. You. You. You. You. You. Stackoverflow.com. Is QA site for engineers, where anyone can go ask a question and anyone can go answer a question, so overflow functions, from a pool of applications. And from the beginning we've, depended, on dotnet, to, drive, all of our applications, and when, we heard about the advancements, in net core we were really excited at the idea we've. Been working on porting, our entire application, over to.net, core one. Major place that we've seen improvement, is performance, dotnet. Core 3.0. Has allowed, us to build a much faster application. And get, information to, our users faster, than before with. Dotnet core 300 we can build the app and run it on our windows developers machines our designers, with Macs and enterprise, in the cloud on Linux and build it one way and that's tremendous, right, now we live on our own servers. In different areas throughout the country and something, we've always wanted to do is be able to use the cloud and dotnet. Core allows, us to do that Asscher is the best cloud platform. For hosting dotnet, cloud. Employees are also much simpler because there's just far fewer moving pieces for, us to manage and deploy and we do upgrades right. Now stack overflows, application, exists, as a large application and through, net core 3.0. We, can add more modularity, to different sections of, the, application so. That allows us to host the different, modules in, different areas which, allows us to experiment, with things like kubernetes. And docker, dotnet. Core 3.0, lets us run any container this lets a ship an appliance to enterprise customers dramatically. Lowering our support costs and making, it easier to onboard customers, we. Can take, a few of our axillary applications, and just make them middleware which means fewer apps to deploy and if your apps to manage its. The testability that it really drawls us to dock that core we can test a method into end server client and do things we could never do before in the old system Batmen, core being open source and on github is very empowering to the community we can find and fix issues and make suggestions for the benefit of every. It's, amazing, to be a part of the.net foundation. What the dotnet foundation.
Is Here to do is support dotnet, developers, throughout the world without. A net course we're just not fighting all of the meta, of building, software which, can actually just go build the software. Hi. I'm Scott hunter and I'm here today with my team to, announce dotnet. Core 3 to, start off let's talk about what da net is. Dotnet. Is this platform we built for building any kind of application you have whether it's a desktop application a, web application cloud. Mobile. Gaming IOT. AI dotnet. Is a general-purpose framework, for building all of these, types of applications. I'm, super, excited to talk about dotnet, core and how. Far it's progressed it's, only been out for a few years and we've already grown to over a million active net, core developers, that. It core is our first fully open source dotnet, framework and. In, the, short time we've actually been open source we've already taken a hundred thousand, PRS. So we're building this not just by ourselves but. With the community and of, course Visual Studio 2019, is the faster, the fastest, adopted, version of Visual Studio ever. Here's. A couple of our customers, that we build. On top of net. We. Have an awesome page on the dotnet website you can go to to see all of, these customers, and read the stories behind them so I highly recommend you go and check that out after the conference. Let's. Talk about NIC or three you. Can actually download this right now you can go to the dotnet website, and get it right now the bits are available, and. It brings a bunch of awesome enhancements, to dotnet core first. Off we, brought desktop, support for WPF and windows forms. Any.net. Core application, gets the ability to be fully side-by-side, and self-contained, meaning, dotnet doesn't have to be on the machine, we. Just introduced we're going to introduce a brand new way of building web applications where every, web application, is a spa and. Then of course we're always making you more productive with Visual Studio C, sharp and we're, gonna talk about a lot of these things today with my team. To. Start off as well, Visual, Studio 2019. 16.3. Just shipped as well along. With Visual Studio 2019, from Mac 8.3. Both. Of these versions of Visual Studio support, dotnet core 3 C, sharp 8 they. Have a ton of productivity improvements, performance. Improvements, and if you're a mobile developer they, support iOS 13. And Android 10, so these for all the latest stuff a. Bunch. Of our partners have released brand-new, tools today, for. Dotnet Core 3 if, you're a web developer and you're gonna use blaze or our new spa application, there is controls. By DevExpress, telluric and more that are available today so. Please try these things out as well so. The. First thing i want to talk about is micro services. Micro. Services is a is, a new developer, phenomenon it's taken over in the last couple of years when. I first arted doing development we build these what, we call monolithic, app monolithic, applications, where you build your database and, your front, end and, your back end all together in a combined application, that, was great when we were had small teams building applications, but as these, applications, have gotten bigger and crossed into more spaces, it's. More important to break them out into smaller pieces so those individual, teams can actually work on those, pieces. So. Not. Only can you build, micro services but you can also host micro services really really well in kubernetes. What kubernetes does for you is. It's an Orchestrator, and that Orchestrator will, basically. Take. Your. Application and, manage. All the components, whether it's configuration, whether it's scaling, whether it's making sure the application is still running well and we have an awesome one of these called agile kubernetes, that runs in our cloud, now. With. Dotnet core 3 it's, the first version of.net core, that really, really really enables. You to build micro services, so. What we've done is we've added a bunch of new features one, is we have something called G RPC, what, G RPC is it's a it's a form of communication that gives you strongly, typed contracts, between the application, but, what makes it unique is, it actually works across all developer, technologies, we're, gonna show it in the context, of dotnet, and c-sharp today but, what's cool is you can actually build a micro service using G RPC and you can call it from Java you can call it from node you, can call it from Python any of the languages you want will support this the.
Next Thing is worker services while. We build great web frameworks the last couple of years as. You start thinking about micro services you want these long running applications, that handle responses, requests. In responses, and so we now have a first-class template, inside, of Visual Studio and dotnet core 3 they'll, let you build these worker services, what's cool about this is you get all the same features you get the configuration. The dependency, injection all the, logging all those things that dotnet core brings or available. There as well we're going to show that a little bit later on and then, finally, as you, build these API is you want to make sure they're super secure and so, what we've done is we've actually, worked. With one of our partners to make sure that you can actually securely. Secure. Your endpoints, using identity server and so, with that what, I'm gonna do next is we're, gonna have Glenn Condren come on stage and we're gonna build a dotnet core three micro service and, host it up in Azure, oh. Hey. Glenn hi, how's it going it's going great why don't you switch your, machine and let's show us your. Service yeah, so a bit of context for what we're gonna do here is I. Am, gonna build this weather micro, services service and then all of my friends after this they're all going to come in and they're gonna consume this thing from an IAS. Cluster, so, I. Am, going to encapsulate the logic of going and grabbing the weather data I'm gonna cache it locally make. Sure I honor expires headers do it's not it's not complicated but it's not trivial so we'll make our own service for it instead of having everybody, talk to the weather API themselves. So. What. I have here is I, have a just, a normal, file, new G RPC service I have, a console, app and I have a standard. Class library we're going to use later but they're all standard, except, that in my weather app I have already set up some config, for the URI and I've put in some user secrets and stuff so that you know you all don't try and steal all of my tokens so. First. Thing we need is a. Worker. So, I am going to add this class we're going to call it weather worker all. Right and. This. Thing's responsibility, is going to be to go and grab the weather data and get it in the cache locally. Ram. And, like this so I have some snippets for pretty much all of my all, of my code and, so this inherits, from background service which we had a little while ago this is how you can add a service that will run forever you, know I've got to some logging some config I need, config to get my URI and then in kubernetes it actually uses the kubernetes config, provider to grab all of the secrets from kubernetes, secrets, which is kind of cool I have. A hard-coded location, ID because you know you don't any other weather than that what's in Redmond and. Then, the, meter this is this execute, async method and, all its gonna do is loop, for as long as the app is going make, a HTTP, client going, to go and call the weather API get, some get some JSON response use, the new system text, Jason that we added to. Deserialize, that, to a type and then cache it and then just can do that every 10 minutes forever, for as long as the apps running and so I'm missing this. Forecast, data this is how. Does, the weather endpoint, I'm hitting represent, the weather and so I'm going to add another class to represent, that, call. A weather model not, see us you. Know if I can not put some some, extra caps in so. What. I did to generate, this I have a snippet here for this now what I did to generate this and what you can do is I just grabbed an example, Jason payload. From the API and I just copied and pasted as c-sharp into visual studio just made this whole thing for me and I'm just going to ignore it that's a cool feature video, convictive take your Jason and can convert, it to see chart types yeah absolutely it's, a super cool feature, then. Okay, so now I have a worker this is done I'm good now but. Except, I need to tell, the app that it's going to go run that worker service, so now, over here I'm going to start doing some code I'm going to add add. Hosted service which is the name of this feature add, weather, worker, right, and, then. This. Needed a few things it needed like HTTP, and like caching right so services. Dot add HTTP, client so I can inject the HTTP client and then I'm going to add the memory. Cache. Memory. Cache so that it has a memory cache right. This, now when I boot this app it's going to go into every 10 minutes ago and get some more weather data pretty.
Simple Pretty cool now. I need an endpoint so. Scott. Talked earlier about G. RPC and some strongly typed this so, so. This G, RPC is a very. Contract. Driven, approach, to our PC so I have a snippet here which, gives me this proto file which is the contracts, for a G RPC, service and, so, I have this. Proto file that says I'm going to make a weather service, it's gonna have a get weather streaming, endpoint. Which it should stream, weather constantly, and it, has a get where though that just returns you whatever the current weather is and, it also defines, what, the actual response type is nice, thing about making our own like. Proxy, for this where the data is we get to choose the actual surface for our clients and make it relevant and not have too much extraneous, data right so. If we just call this weather dot proto and then, in here the way this actually works is in my CS proj I have, this protobuf, element, which, references, that weather proto you see the rename worked good job team and it. Says it's gonna generate server, because the way that G RPC, works is you, create a contract, and then you generate a lot of code and you just deep lament the bits that matter and you leave all the rest to be generate write I write that contract, and I generate either a client or a server using, the tools yeah, exactly and. So then we're, gonna go create a weather service now from, my from. My snippet, and so. What, we have here is a service, that implements this weather base and that's that generated, code that, we just talked about well. So we're just controlled on the way to glory here I have the base class I have a memory cache because I need to get the data out of the memory cache and then geo PC doesn't want you to have empty method calls but because I'm hard coding the weather for Redmond in this case I've just, got this empty type to to fill in for the request type you, would probably in most cases have an actual type here that has your data right yeah past your location, or something yes I think yeah and then I just have this get current weather response, all it does is left hand right hand code to say take, that just pasted, code the pasted model earlier converted, to the one that we want to actually give to all of our all, of our friends later and then, get where the returns one and then forget where the stream it just loops for as long as the person is connected it. Just grabs the data out of whatever's in the cache currently, and then loops, right. And then this is every 10 seconds, just so that it's easy so you can see something for the sake of the demo we might actually even make this two seconds, just, so you can see some data constantly changing, we know the data will only actually change every ten minutes or so but, you want to Keane just can to kind of keep a constant stream happening, right and, then that's it that's greatest service so if we will rename this to Weather Service so that yeah. Just because we. Can't have a class with a different file name it'd, be terrible and, then you know startup CS the way you register, these services, is we have a map GI PC service endpoint, right. So. Now I can change this to Weather Service and, that's it at this point my app can run and it'll go do its job and so, now you, want a client, to go grab some of this weather data to test it out so, I. Added. This console app earlier conveniently. But, I also added this weather client lib so I could, go, over here to my client console and then add a ref to the proto file and have you generate the client code straight into my console app or any other like dotnet stuff that we're gonna show today but, what I can also do is, I can come over here I have a completely empty net, standard class library, except for like the default class which, I'm going to delete all right, and then, I can, right. Click on this and say add service. Reference, and then, click add new G RPC service reference, browse to the proto file that. I had earlier, that are the same profile, that my weather app is using to generate the server code and then. I can say generate, client though here in this drop-down right. Instead of there's some other options for what you can generate I'm generating a client in this case and, then just going ok this, is gonna go install the new Getty goodness that you need to make a Geo PC generate code and generate all the types that you need this is pretty cool so you built a service we've built our first micro, service we, installed GFP C into that mm-hmm, and now you want to write a client so all you had to do is basically reference, that same proto file from your service in your client and, we'll generate all the code for you absolutely and you just then you generate you kind, of the basic yeah generates you all the codes for the clients class yeah absolutely they're not all gonna do is new it up and start making calls yeah and so let's look at what that looks like so I'm, just gonna add a normal project reference, now to my client class library, because everybody.
Can Now share this net standard class library, that has the client code generated, in it or, they can choose to reference it directly and then, in my program CS I have a have. Another snippet here where, the client alright, and, well, I think it's actually the whole the whole class idea this time and then. What. I'm so yeah you can see here like as you just said this, where the client was all generated for me I just I just knew it up I used this channel type to give it the address and then I have a strongly, typed method, forget whether async which was my contract, file you start calling them and they start getting results back and write them out to the console absolutely, so now I can like control f5 this, weather service you, spit up on my local machine you'll, see they will see the console output in a sec it's, gonna see the output go fetch the data and, then sit there and be a gr PC and point and. Then so, here you can see it going and getting the data and then being ready and then, over here I can then like go debug, start new instance of, my of, my client, console and my. Client console a ping up its gonna grab a single weather and then just say done in this case cuz that's I'm just grabbing is calling, a single weather. Endpoint. Asynchronously, I'm using async like console, app that we added a little while ago and, then it's like apparently 53 seems, reasonable. That's pretty awesome so in just a few minutes we. Built a brand-new project using the worker service a long-running, process with like Yuma drill the micro service yeah that, goes out and fetches weather from, an, in point somewhere and then, we actually added G RPC to that service, so, a client, can call in to that and get that weather data back yep absolutely let's, switch back to the slides for a second and. We'll. Talk about c-sharp, so. Along. With that net for three we're also shipping the next version of C sharp C sharp 8, it. Has a bunch of new stuff and we kind of broke it down into buckets one one of the things we think about is we, always want to make your code safer. To write want to make it easier for you to catch the errors early or prevent. The heirs from ever occurring and so there's some new features of called, nullable and c-sharp 8 to try to address some of that stuff modern. As well as we as we look at language, we. Always looking at other languages, and we're looking at the patterns that developers are using today and so one. Of the cool features we have in c-sharp 8 is, async. Streams and. We're gonna show those in a little bit and then productive, we always want to make you more, productive so the goal of c-sharp is to add the right features and stuff to make it easier for your write code and write code faster, with less less, text in the screen at the, same time also tooling. All that with Visual Studio family. So, you can actually be, more productive so what, I'm doing next I'm gonna bring Mads on and we're. Gonna take the demo that Glenn had and, you. Know Glenn didn't really write it the best way you could we're gonna we're gonna make it use async streams, well. I think Glenn, did a fantastic job it's. Just that when. He switched. Back to the last let's switch back to the laptop and. Look at the. The. Proto file that, Len put up there there were actually two endpoints here there was a get whether that he used that he called just before from the client and there's a get whether stream which continues, to stream whether down so. That's the one we're going to investigate. Now and find my way back to the program here. So. There's if, you look at the, if. You look at the client here, it. Also has a get, whether stream method, so that's probably the one we're going for and. That. Can't be awaited. Instead. We get something. That we can explore a little bit so let's just call it response, for now, and, let's start drilling into it so if we say responds. Dot we. See that it has a response, stream that sounds stream e let's do that, and. That one has to read all async, that sounds, streaming. And async, that one's pretty good right let's do that one, so. If we call that. Then. What do I get back that's we. Can actually drill into that as well let's try to it just f12 our way through. There's read all async, it. Returns, something called I think, enumerable of T and. I sing and horrible if. People remember I know mobile is the core type and I know mobile of T is the core type and net that, you can for each and. And.
Produce New ones from, the language as well with with, yield return with iterators, and so, I I think normal is just a it's, just an async version of that we can actually take. A very quick look down the rabbit hole here icing. Your normal ball, just. Like enumerable. Has a getenumerator, this, has to get async enumerator, and if we drill into that you. Can see that it has a current property for the value that we're currently looking at and it has a move next method but, this one is async right so if you think about it this is a stream where you can pull elements, but every time you pull a new one you do it asynchronously, so it might take time and you might you have to wait it okay so, that's how that works under the hood now at. The language level we would like to support for reaching over these so let's try to for each over there, the. Thing that we got back from our drilling here so let's call that for. Casts. With an S because. We hope there are multiple and then, we can let's try it for each over it for each bar for. Or cast in. Forecasts. Um. Now. What we get is oh this thing can't actually be for each you, and. That's because, in c-sharp we decided you shouldn't just be able to for each over acing things because, then you can't look at your code and see and know the racing and know that you're doing something anything right we want every weight to be visible in the source code so you can know that you're sort of getting off the thread you're doing an icing thing you're it's a point where your context might switch and so on so. What. We have instead is an a weight for each syntax. That then you. Use when you have an eye and. Eye async enumerable and let's just put the right Curly's in there for for. The beauty contest and. And. We're good so, now we've actually called. This training in points and now, we set it a async, loop around that endpoint yes, it the. Code honestly to me Mads you just took a for each and an edit await in front of it yeah, it works I tried to make a big deal of it but it's actually very amazing, I mean yeah it's, it's a complicated feature but it looks so simple when you actually use it right and some you know they're more there's more to it you can actually yield return in an async method as well now returning, icing you know mobile so we have you, know a sink.
So Let's switch the machine here. And. The theme we're gonna have today is, as. We start building applications, you know we built that micro service, now. What you're gonna see us do is basically build more, applications, on top of that thing showing you can build on it everywhere, and. Share, your code right. So, I happen, to have a weather application myself. And that's application. It's a VIN firms app that, sits on your desktop, and shows you what is the weather right now let, me show it to you it's. Very simple and but, it has one problem, I haven't, actually finished, development. Of that app I put, together UI, I put, some dummy, data that. Shows the weather on Alderaan, planet, right now. Planet doesn't exist anymore so I, so. Cold, yes, but. I would. Like to actually. Show the real data for. Say. Seattle, and I, just heard that Glen has amazing, service, running in kubernetes, and he also has a client, library, that, I can just use and moving from supplication, to that right and not. Only that we can actually use it from any dotnet, application. Right mobile, web. WPF. So. Let's take a look at the library that Glenn created, for us, if. I right. Click on, properties, I. Can. See that this library is, targeting, dotnet standard. 2.1. Which, is great because that's the latest version of.net standard, don't understand or two point one ships with dotnet core 3 so it's the it's the latest version under standard the support sneaked or three but it also only, runs on down in core 3 so that probably means yes. Executive. Your application, of donek, core 3 desktop, a+, no its framework, because i developed, it a while ago where, i did not have a choice, between core, and framework, so, if we go to properties, we can see that my app is targeting, dotnet framework 4.8, I, cannot. Reference, the library, right now but what I can do I can port, my framework, application. To dotnet core and then, I will be able to use Glenn's library, and to. Do that we created a tool called, try, convert, that will take your, dotnet. Framework project, file and it will try to convert, it to new, SDK, style, net core project, file it's, a simple, command-line tool I'm gonna type try converting.
Z And as a parameter I'm going to send the path to my project, file and. Understand. For. Donnie core the, project files are different than they are for done in trailers and so what we built is we built a global, tool that can be installed on a machine it's a sample to. Help people convert. Their CS proj from an old-style cs proj to a dotnet course now see yes exactly and now. When. I click on properties, in my visual studio I can, see that, now my application. Is targeting, dotnet core 3.1. Right. So is in just a few seconds, i ported my framework application. To dotnet court so. Now i can reference. The, library, and to. Do so i'm gonna right click on dependencies. Add reference. Find. Weather client. Sleep. Click. Ok and. Once. I did that let's go ahead and update my code that is pulling dummy data at this moment so, I have this method, pool weather that. Just. Gets demo data and I'm. Not, gonna need this. Code anymore, I will. Also not need they, get, damaged data and here. I was using the, local. Weather, response. Class, but I'm gonna be using the one from the client, library, so, I'm gonna delete that code as well now. I will insert, a few. Lines of code, I will add users, and I will talk to those lines. So. First thing that I do here, I'm creating, a client, from. The library. Then, based, on that client, I am creating, JIRA PC weather forecast, service, and, for. This forecast, service, I'm calling, get streaming, weather so every, time the service, on kubernetes, is sending, out the weather data, every. Two seconds, I'm getting, the, data. On my app and. Let's. See how that works so. This, code looks almost exactly like, the same code that cool yes, yes exactly second, ago what they were calling my name await the same stuff yep, so we're showing sharing, dotnet code across all my application, types. And. That, looks like a real data Seattle. 53, degrees and, weather. Doesn't change that often but you can see that I am actually receiving. New data every, two seconds. So. Once. I built the, application. Now I probably want to share it with my friends maybe, even, community. Right I'd love to have it have us look at that new feature we talked about single XE that's, that's, a great idea let's publish it as a, the legacy file and to, do that I'm gonna go to project. File and. Let. Me move everything down. So, it doesn't distract us and I'm. Gonna insert three. Lines of code the. First line published, single, file will. Make package. My application. And dotnet, core in the single is all. Done it cool all your application, is at one single type Z yeah so, nothing has to be on the machine that you give them exactly, yes it's completely independent, from, the environment it's gonna be running on the cool the second, one runtime, identifier.
Specifies. Which platform. I exist. Should target, and by, default that Network and run on any platform but. If we're publishing it as a single MZ, file we need to specify runtime. Intensifier, and the. Third one is published. Three that is a new feature that will, trim out all assemblers. From your.net core. That, are not used by your application, so, that way you don't get the entire, dotnet, core, you get on the assemblies that you need for your app which, makes the size much smaller. All. Right once, I added that to my project, file I'm gonna right, click and. Go publish. And publish. One more time and while, it's publishing, we, can see that, here, you can specify the password. That symbol, exe, will be put you, can also specify, configuration. Target. Framework, target, runtime, all those settings can be set from this page as well and. It. Takes a while because right now dreamer. Feature is working so it's actually analyzing. What we can throw, away if, it goes and looks at your app figures, out what the dependencies are is best and it's not perfect we call it experimental just yes so yeah you might find it it actually trims too much stuff out and you have to go back to your CS proj and manually reference. To whatever it turned out to hard that is true it will build better tech around this in the engine we're gonna build better tooling but it is a first. Step that we wanted to ship and on eight core three yes. And as you said if it trims something, out it's very easy to edit back to your project row okay. So we. Published our single. Eggsy. And here. It is just 1x, if I'll that they can send to my friends that they can put, out for the community and, they, will be just able to run it and use the app on any computer that has you don't, even require down in core yes, yes, so, the last thing that I would like to show today is an integration, with App Center because. As you mentioned web developers, have been spoiled for a few years where they could see, analytics, for their websites, they could see how many users they, got which devices, that what it was accessed, from and so.
On And we would like to enable our desktop, developers, with the same features so. For, that you, can use App Center let, me go to my, epicenter. Portal. It's. App Center, dot Emma's I created, an account and, here, you can create a new application you can configure it but I already, did it for my app it's weather Vin forms up once. You do it you will get very detailed instructions. On, how to add, integration. With App Center in your program, and it's, super simple you just add a few new grid packages, and then you, add a few lines in your project, program, dot C s file so, I will, do exactly that I'm. Gonna first go and add new get packages, that are required, which. Are. Microsoft. EPS. Enter. Analytics. And. The. Second one is Microsoft. AdCenter crashes. Right, once I edit it I'm gonna go to program. Dot. CS file and I will add. Some. Museums, and. This. Is how I enable. App Center in my app lines of code yeah. It's, basically, just one line app Center, dot start and I send the key that I get from the console, and I specify, what I want from my app. Center it's analytics, and crashes now, you'll get detailed crash analytics and you're gonna get monitoring, as well letting. You know that people actually tried the project exactly, and. I'm. Gonna run it but it will take the portal, a few seconds, so if we go here, and we. Go to analytics. You. Can see some analytics. So you can see that I was testing that demoed September, 20, and September. 23rd, just, today and you. Can see a few spikes we, will have another, demo, later today with, Danielle, and Matt that will go deeper. And dive into all details, of all the great features that App Center can offer and. Was, that awesome, so so to, recap what you can do now is you can basically build, desktop. Applications, with dotnet core 3 WinForms, in WPF, you. Can make them into single eggsy's it can easily be distributed. You can add rich analytics with, Azure, App Center awesome. I'm so so. Excited about this so, let's move back to slides. Next. I want to talk about mobile app design right so, xamarin is awesome. Technology that lets you take all the goodness of nets and make it available to all the mobile devices. So. The idea here is you can build any ios, and android app, with, c-sharp and why. Would you want to do this well you want to do this because dot, nets got all this rich libraries, that. You can share across, all these applications so for example that, micro service that we showed before we, probably, can share that across, Android, and iOS that's. One of the tenants of dotnet. And c-sharp. And, xamarin. Is being able to actually share the, same logic across, all your app types. Android. Or iOS. Another. Cool part of it is we have a library, for building apps called xamarin forms basically. You build it once and it runs on all the devices, and, of course also all the xamarin tech is open-source like. The rest of dotnet today. We have two awesome announcements. The first one is sam'l. Hot reload imagine. You're in your application, and you're gonna change some of the sam'l files well, you don't really want to recompile. And republish and wait for all that kind of stuff to happen what. You want to do is you want to basically save your sam'l file and have your device refresh, immediately. Even. Better than that sam'l. Are xamarin. Hot restarts, which is the ability to also change, the source code normal when you change the source code that's a full recompile, copy, back to the device I, wanna, be able to change that code and refresh.
Pretty Fast as well and so this one's in private preview today you. Can go to the URL and sign up and you might get access the. Hot reload is actually available to download today, and so, next what I'm gonna do is I'm gonna bring up James and he's, gonna show us how to put some xamarin apps Oh awesome. Thank You Scott so much I'm here in my way cuz you know I need to get to my Mac get to your man okay awesome well like Scott, said I love. Donna. Development, with, xamarin. Inside, a visual studio what, I love is that like Scott said you can share all of your c-sharp, and Donette knowledge across, all of your applications, and that's what we've done I decided that I wanted to take that weather app import, it to iOS and Android and at, the same time leverage, that same exact 2g RPC logic, that, only to use and that we're gonna use throughout the rest of the day now, two important, things to remember like. Scott said we have all sorts of different texts of pieces. Of technology, for cross-platform development, but. With xamarin you have access to a hundred, percent of the api's in ios and android and always. Up to date we just shipped iOS 13 and Android. 10 support so, on top of that we have xamarin forms for cross-platform UI and xamarin essentials for cross-platform native, API access so, let's go ahead and port, that, exact, same weather application to iOS and Android taking. Advantage of mobile features so. Here I am on my Mac which suits the Mac yes there's my Mac boom and of, course I need to get started with a great design I'm not a designer Scott sorry but. Guzman, bar Qin was nice enough to have this amazing weather application on, up labs which is one of my favorite websites to use for mobile design and reached. Out to him super, happy that. We're able to use it and I'm super happy that he's an amazing designer, so, that's what we're gonna do and I'm, over inside a visual, studio for Mac we, just. Launched, a brand-new version with all sorts of new tech so I want to show that off too but, where you get started is file new project you, have cross-platform, apps, you, have iOS, Android. Dotnet, core apps as your functions Mac TV, OS & Watch OS everything, is possible. With xamarin, and dotnet, so. What I've done over here is I've added an Android, and an iOS project, and I, also have this mobile, core it's, a dotnet standard, library, just like we can use to share across all things, of dotnet but, it has xamarin forms in there and this is my mobile, specific. Code so, this is things like my user interface with, xamarin forms, my models, my view models my app state but.
Notice That I have that wider client. Lib that olia used that Glenn had created, so it's inside a visual studio for Mac and I can reuse it right here inside. The weather app so that mobile core that's the differentiator, for xamarin right that mobile core is the code that is shared across the iOS and Android apps right at once and it gets to be used in all the all the devices you can think of it most my apps have two different donna center libraries, one, that can be shared with anything. So restful, service calls models, things, that are just hey this is Donette code then, I have my platform specific, code or mobile specific, code and this UI runs, on iOS and Android right so so. For instance here if we take a look at how I built this app is I have a weather page and a weather view model so. Here up top I. Have a view model I have, a weather. Client, and this G RPC, weather forecast, service the same exact code that olya was showing earlier and since. I'm going to be using sam'l, and data binding I have some backing fields, so for instance I have a use Celsius a temperature, condition. Time stamp these, are things that my user interface is going to display, and, I can tell it to update via, set property, but, here if we look at this message. Weather service get streaming, weather same. Code the, only difference here is that I'm telling it how to render. The user interface, so here's a bunch of items I want to display in a list and. Then when I want to update the UI I use Samer and essentials, to say begin invoking, this logic on the UI thread because that G RPC could be coming in from anywhere right so, let me just go ahead and run this really, quick so I'm just gonna hit debug, this, is gonna take my application, logic compile, up my Android application, and then, deploy it to an android emulator right. Here running, on my Mac so. There, we go my. Application, is starting up and. What. We should see hopefully is a beautiful, weather application, that I built inside. Of zamel. Alright. It's. Doing. Some stuff but let's go ahead and fill this in a little bit more so. I have my user interface code, down here and, let's. See here I have a, pancake. View, which, is a beautiful third-party. Control, that. Will allow me to do the gradients, in the background. Think. I'm missing some stuff okay so I have a label with nothing in it so let's just put in Seattle, now. I'm gonna use that zamel hot real Oh so I'm gonna hit command, save it's. Gonna save that and push the changes over, into, my device so Seattle, right there, now. What we can also note down here is I'm missing some other things, in my UI so. For instance here we can go ahead and maybe. Put. In a new column, and, then I'm, gonna say binding, and the. Brand new sam'l, intellisense, will kick in and I can say temperature, there. We go now. It does look like for some reason my. Internet. Has stopped so that's good and I'm, getting no updates so things are working exactly as planned because we're doing it all alive just. Super great but I have zero degrees so it did show up so that's really good all, right very cool it's, very cold in here yeah so, other, things that we can do inside of here for instance is like this this Monday here so that's just showing a blank so. If I look here on the date what. We can see is that I. Have. Current weather conditions, I have this date property, here and maybe I want to change this to a. Capitol. Casing so I can say use a case. Converter say, true hit, a save and now, that Monday is completely, updated, 100%. Now. What I'll do here because I did change internet right before, we're, gonna go ahead and stop and redeploy. Again and. Bring up a new emulator and, see if we, can get our internet back on our machine which. Would be very helpful if so you. Can see actually how fast the emulator, rebooted, here so let's go ahead and see if this is gonna spice. Up for me cuz having real data would. Be useful always, fun to show the real, microservice. But, you can see how rapidly, iterating. I was on that user interface using zamel ha reload, inside my application, so, there we go we have leather oh hey cool. So one last thing I want to do down here actually two things is I. Like this collection. View which is like all the different humidity, UV, down here and that's a brand new feature inside of xamarin, form so here I can say horizontal, or vertical but. I'm using a pancake, view so I'm gonna add a fancy corner, radius here and hit save again again. Zamel ha reload kicks right and boom I got beautiful rounded so fast so, fast but, you know I like teardrops. Which are new hotness I think everyone's gonna pick up boom look at that and, I can prove that this is running in real time because down here if I wanted to I could, go ahead and say time stamp large, and now we can see the time stamp from that gr PC client updating, in real time or right there which is super awesome and that's, zamel ha reload. Right.
There Inside, a visual studio for Mac with all that gr PC client beautiful. User interface, boom right there now. What. I need to do though is also deploy this to iOS so. Normally I would just say you know set that as my startup project go into my iOS simulator boom good to go but I want to show off some brand new features of hop, restart. So I'm gonna actually head to my Windows, machine right, now and do iOS development so let's swap places over, here I love this here we go Android on the Mac and iOS on, the Windows machine that's correct, so, I'm right over here now. What I want to talk about though is that it is the same projects, same, solutions, that, I just had open in Visual Studio for Mac so, no matter where you're working you're, good to go I know your Mac guy I'm, a Windows guy so ideal. Setup right, here so. That's gonna make it really easy to go back and forth and again I have my shared code and I, also that I project. And that shared code and everything else that I have in here now. What. We wanted to do with hot restart is that every, once in a while you're changing c-sharp. Code for. A saml hot rila user interface code you need to be able to rapidly, iterate on your app but, what happens when you want to get it on your device and. That's some of the cool tech built into, hot restart. So what you're able to do and what I have here is my iPhone right here my iPhone 7 that's plugged in to my Windows machine ok, and, what. I have up top is, my iPhone, right, there it's connected it's good to go and, what's nice here is that all I have to do is hit debug, if you've ever done this before you got to worry about configurations. And connections, and profiles, and circuits and all this stuff but, what you're able to do with this technology is. Restart. Your application, directly, on to, your device so. Here, for instance I have my device. That should be screen. Mirroring let's, go ahead and see if it's gonna cooperate, with me, let's. Go ahead and maybe shut. It down and reopen, it let's. Do this really quick here there. We go and. Perfect, so there's my device I'll, put it right over here so. There's, my device right, there on the screen now. What's great about this is that I can come into my, UI, let's, go ahead and just make this sticky on top cool that looks good and, what, I can do is add some new technology. Into here so for instance maybe I want to convert this into Celsius. So. Again I'll just uncomment, some code I have a checkbox I have a label this is data bound to that use Celsius I'm gonna, hit save now, zamel, hah reload. Will kick in and notice that it's reloaded, I hit a breakpoint I'm debugging my, app right. Here on, my device so I can go ahead and continue on good. To go. All. Right that's good I must have made some changes to my code that weren't compatible but, no worries I can just literally use. Hot-hot. Restart. Here to redeploy again, so, let's go ahead and deploy there, we go and, you just saw like I stopped took, that took some changes good to go I see, you back on the phone already and that's back on the phone yeah so, this is initial, that debug session and, sam'l, ha Rilla so here's our app here's everything is good and now we have this little back. And forth but as you. Can see Scott or, have some issues because I hot, reloaded, that UI but. The temperature is not changing now, the background is so my converters, my code is running so, let's fix this if. I go into my, view model here we, have that temperature, property, now. It's returning temp so that's not good so what I'll do is I'm going to say use Celsius. I full intellisense, everything, here we're, gonna use xamarin essentials, what's cool about this, is it has a bunch of unit, converters, built in so. You can do like Hertz 2 degrees Kelvin to Celsius here I'm gonna say Fahrenheit, to Celsius and. I'll pass it the temp else just temp there. We go make. That temp there we go now. What we can see is that. The UI is, telling, me that hey I've made c-sharp, code changes, to my application, you, need to restart, your app and what we can do right here is hit the restart button, and this will take all of my code changes, that I made redeploy. It to my device without having to compile it at all and what's. Great is that this is literally right to my device in just, mere. Seconds, those squiggles go away, the application, is now back, into, a debug, session that. I would expect earlier and what. We should hopefully see here once ha reload. Initialize, I can it Celsius, now. We're in Celsius, and I can use my app my, real data use ammo hot reload for my UI and ha, restart.
Component. Class libraries, I'm gonna add a new project to this solution and this, time instead of a blazer app I'm gonna pick a razor, class, library. Now what is that well, a razor class library is actually just a normal dotnet standard class library, but it's been set up to also be able to compile dot razor files to compile razor components. Here we have a razor component, that's in the new class library, it's, pretty simple it's just a div but, it does have some styling, and this is interesting the the project has this WW root folder with a couple of static files it's kind of styles that CSS, it's got a background image that's also used this, is a new feature in asp.net core, in dotnet course Rio where, your class libraries, can carry static files that then are made available to. The application, when, the project, is referenced, or when the nougat package is referenced, so I'm going to add a reference to, that class library, like so, so. I can use that component now, to make the these files available in my app I do have to add a, linked to the styles that I want and we use a simple convention, to do that I'm, gonna copy this existing. Link. And I'm just going to update it so the, convention, is its. Underscore. Content, is the the prefix and then the name of the class library so razor class. Library. One and then the path to the file that you want so Styles dot CSS and that's all you got to do now, we can use our component, in our app so let's just start typing here component. One I think is the name yep there's intellisense, let's, close that out we, say just go back to the browser you can see that the browser already knows that the app has been changed, we just refresh and so we can hopefully see the changes on the home page aha, there, is our styled. Component. That came from that component class library easy so simple so, that gives us hopefully the basics that's not going to build that weather app I've already started it over here and, this. Solutions, we go into the blazer folder, I'm, gonna set the blazer server, version of this app as the startup project there we go now this this blazer, app is a little bit interesting in that there's no much in it like, it actually doesn't have like hardly any RAZR files in the app project, like. Hardly at all that's. Because it references, this blazer, weather. Core project, down below that's a razor class library, that, contains all the components, that's used by the Apple explain, why we did that in just a bit but you can look in here and see there's the forecast. That razor page and there's all the razor syntax, that renders the app let's go ahead and run this let's. See what the app looks like this, app borrows, the same beautiful design that James, used for the mobile application, there. It is so looks pretty good we got the current temperature that's all working now let's look at the code and see how that is done at the, top of this page it's got a route just like before it also is injecting, an eye weather forecast service that's the same G RPC based service that Jay Mewes use in his mobile app same code like so lot Annette yeah, all the code runs everywhere browser, mobile, desktop, anywhere. You want and then we've got the razor markup that's just rendering out the the Dom elements, for that for the page down. Below in this code block here's, a component. Lifecycle event that fires when the component, has rendered and this, is kicking off this get weather updates, a sync process which is in this method down here here you see that async, for each loop that we saw before you've seen before so it's getting the live updates, from the server we should be able to see that in the app if I let's, zoom in here so, 42:45. Yeah so that the tics are coming in from the migrating.