Develop .NET MAUI Apps on Linux with VS Code: Complete Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my friend tucks here and I have created a complete guide on how to get started with dinette Maui development on Linux deploying to a physical Android device and we're going to show you in this video right now so one of the questions that I always get is like hey can I now develop.net Maui apps that run on Linux and the answer is no unfortunately we don't have a Linux Target yet who knows what might happen but we don't have any plans for it at the time of recording but what you can do now is develop on Linux with vs code and deploy to Android so Android is the only Target that we support right now When developing on Linux so on Linux you can install vs code the Dan and rally extension all the stuff for your Android environment or your physical device and then deploy to that so you can get building with Don and Maui apps on Android and from there work to I don't know your IOS app or your Windows app or whatever you want to do so that is really cool right and in this video I'm going to show you all about how to do that the steps you need to take everything that you need to set up the things that you do need to set up from the top of my head is like the download SDK we're going to see that open jdk 11 from Microsoft that's what we're going to see we're going to install vs code we're going to install Android studio and I'm going to show you all of that step by step it's a bit of a rough video it's a little bit raw I'm going to make some errors here and there as well but that will show you what things to run into exactly where to click where I got my stuff and you can find all the links that I used down in the video description below so basically let's just get to it all right so let's get started now right off the bat you can probably see that I have a bit of a complicated setup at the bottom you can see my windows 11 taskbar so that's my host that's my physical machine I've got Windows 11 installed on the left you can see hyper-v on top of that with a VM installed with a clean install of Ubuntu Tony 2.04 I think the latest LTS release right now so I got that installed now it's been a while since I touched Linux so I had to figure out a couple of things and I'm going to assume that if you landed here you are a Linux user so you probably know more about Linux than I do and that also means that you know more about your Linux digital distribution and your Linux installation than I do because there is a gazillion distribution right so things might be a little bit different this works for Ubuntu which is I think a fairly popular one and that works with other popular distributions if you have a more complicated setup you might still get some information from this video so be sure to watch it all but it might be a little bit different for you but your this Advanced Linux user right so you can figure it out okay so we've got that um and then here on the right I have a physical device my physical Android device I got it right here you can see it kind of like mirrors the same screen um and um I need that because if you have a virtual machine with Linux then the emulator that you're running on Android is going to be another virtual machine right so and that nested virtual machines virtual machine Inception doesn't really work that well usually so I couldn't get that to work maybe it's just impossible so I had to use my physical device so as a bonus you're going to see how to do it with a physical device but also I couldn't really get my USB port to connect to the VM so as an extra extra bonus I'm going to show you how to connect through Wi-Fi with your physical Android device to Linux for debugging so bonus at the end of the video make sure to stay tuned all right so um again I think also with the emulator and virtual machines if you again if you're a Linux user I'm going to assume that you have that installed on your physical device and the emulator later that is going to install I'm going to show you how to install it is going to work just fine right so you should be able to just use that all right so back to the task at hand this is a clean installation so I opened up a terminal if I do.net Dash info it's going to say hey I don't know what.net is right I think Ubuntu in some flavors comes with net prepackaged that would be great then you already see the info here you can skip this step but else you will get something like this and it recommends me like hey but you can get this through Snap now in my time when I touch linuxnapped wasn't a thing and I think that some kind of new package manager which is really cool but please don't use this because I did this and the way snap works is that it creates a read-only part of this package on your disk and then if I do Network load install to install the dot and Maui bits it's going to say hey this is read only I can't install extra stuff here which is a great security feature but not great for what we're trying to do so don't do this now I think you can also do apt-get right it says something like that as well maybe you can get that to work but I couldn't figure that out so what I did is turn to my browser and I googled with Bing to install.net7 and I landed on this download.net7 page and here you can download like the package manager instructions you can download the binaries for all of course Linux Mac OS windows and what triggered me was like this hey.net install scripts that sounds like something that I can work with right I have the script I can see what it does so let's just try that so I clicked on that and here we have a scripted installation so you have this install script documentation so that's what we I looked at that as well I will put all the links down in the show notes so have a look at that if you want to follow this along um so I I'm going to copy this URL right here and I went to this documentation and um here you have this reference right so you can see what is going on so by default this is going to install if you just run it if you download it and run it without any parameters it's going to install the current LTS release which is done at six um which is great but dotnet Maui does not follow that same pattern so for net Maui you want to have.net7 right so I want to have.net7 installed and that's what I'm going to show you so here if you scroll down yada I don't even know I think somewhere I found that options I'm not sure oh here we are so we have this channel SDS LTS or you can just say hey give me this two-part version and and we can do that so dash dash Channel that's what we want to do okay so let's go back to my terminal and I'm going to say w get which is a client to download whatever content is behind this URL I'm going to paste the URL in here and it adds these weird characters it does that I don't know why but let's get rid of them so I just want to have this one press return and it's going to download this script so if I do now inspect whatever is in this folder I see this.net install script you can't execute it yet so let's do chmod plus X Plus execute.net install so now we can execute it and you don't need any administrator access for this so you don't need to do sudo or anything you just can run this script so dot slash.net install and I'm going to say dash dash Channel 7.0 right so I want to have the 7.0 Channel and it's going to download it now you can see here 7.06 306 that's the latest version at the time of recording so it's going to download all the bits it's going to put that in the right place and then I do have to add it also to my environment variable so that it can find it in the right places so for Linux at least for the vs code stuff is it looks at the environment variables that are somewhere so you can see added to the current path uh we'll only be visible when sourcing script so I don't know if it's supposed to do this automatically it didn't do it for me so I'm going to do it manually um but yeah you I'm using bash so what you want to do is find your um let's see ls-al we have this bash RC that's where you put your variables for bash again I'm going to assume a little bit of knowledge about Linux if you're interested in this so let's just open that open Dot bash RC I don't know I I tried to do it with Vim or VI and I got stuck I never got out of it I had to kill the VM burn down the whole house to get out of him so I'm just going to use this notepad I'm kind of a a lame Linux user but I'm going to add here at the end I'm going to say export actually I have it copied here so let me just copy it here from off screen so that you don't have to watch me typing and paste it in here and it's all the way down here at the bottom let me give a couple of extra returns so it's in the middle of your screen and we can say export so now we create this new environment variable basically.net root is home and this is a built-in kind of environment variable which is your home directory dot dot net so it installed it in my home directory and then we do the same for the path so path is kind of like your Global where all the paths is whenever you type this command like chmod is one it's going to look into this path variable to find where that executable is and I'm going to add the path and then do the.net root and dotnet root Tools in there so now we have the path set up let me remove the extra things here and I can save this so Ctrl s and now I have to reload this so you can either restart this terminal window or you can just say touch dot back RC touch is kind of like hey reload it and whenever I dot net dash dash info now you will see that it still doesn't work okay so oh it wasn't touched it was source source uh dot bash RC sorry touch is another command that sees if you're but you know it kind of like updates the last modified date of your file I think so source that was the one I was looking for now.net dash dash info that will show me.net info so.net is installed successfully and I can see a couple of things so runtime environment oh actually the version uh the commit find runtime environment Ubuntu so more versions SDK installed so that's the thing that we're after and we have these runtimes installed and done at root is set and it's set to this path so we got all of this which is great now what we can do is we can install the dotted Maui workload and with the workload only on Linux is only Android is supported right only targeting Android so if you dotnet sorry workload install Maui is not going to work at some point in the process it's going to crash because it says hey this is not supported on Linux which makes sense so what you can do is say Maui Android and now it's going to work because it only takes the Android bits and installs that on this Ubuntu machine so this is going to take a little while I'm going to let this run in the background but whenever this is finished we have the dotted Maui Android bits on our machine and we're ready to build Android uh the Android apps with dotted Maui basically and also Android apps built on.net7 but who wants to do that just use Maui alright so we'll let this run at the same time the other thing that we still need to install as well is the open jdk so that's the kind of like Java development kit right and Microsoft has its own build of that and we need a very specific version of that to work so again search with being like Hey how do I install openjdk again the link will be in the show notes as well and you will land on this page and here you can see install Windows Mac OS show stick more install on Ubuntu hey that sounds like us so let's click that and here we have again some scripting right so this is going to capture the Ubuntu release so it's going to get the version number from our system in a variable and it's going to do that wget again to get some package from here and it's going to install that package and then afterwards or it's going to add the repository to our package manager that's what it's doing here and then after which we can install this openjdk package right but be careful because this 17 one is not the right one with that it's not going to work you need 11 right so make sure remind me whenever I'm going to copy paste this then I change that all right thank you this is on you now um so okay we're going to copy this I'm just going to copy this well again copy this in in one go basically let's see if it doesn't add the weird characters because Elsa will be in trouble this is still running I can open a new tab because this is not you know this is not going to interfere with each other so let me zoom in so you can follow along what's going on here and let me paste this in here so this seems all right so let's just enter that I need to do sudo so I need to enter my password here and it's going to add the Microsoft repository now to my system so that happened and you can see it picked up on my Ubuntu 2204 it's all set up now I can go to the next command and again I'm just going to copy it until here so the 17 so we don't get the right one thank you for reminding me and now I go back to my terminal and paste this in here paste and I'm going to add 11 on here and then I'm going to press return and now it's going to install everything for open jdk 11. so again uh one of the prerequisites checked we got it done let's see how the other window is going this is done successfully installed workloads Maui Android cool so if I do.net workload list it should now have Maui Android and you can see manifest version so this is something that you should check if this is in here everything is set up properly your.net installation your.net SDK Works your.net workload Maui Android thing works that's all in place open jdk do you want to continue yes let this go on for a little while and while this is going on let's install two other things first let's end install Android Studio and here I have another kind of like app store which is Ubuntu software uh which is really great which makes it really easy you can probably also use Google to Bing Android Studio install download that through the right things but I would assume that the most modern Linux distributions now have some kind of app store right so we have that in this case I'm just going to use that so I'm going to search here and I'm going to search for Android Studio because that will bring in all the things that I need to build stuff for Android right so this is not strictly necessary you can also install it with different things there is some documentation with the vs code extension the dot and Maui vs code extension as well we have a build Target for DOT and Maui which brings in all the necessary stuff but I just like to do this because this also brings in the device manager and the SDK manager and the emulator manager so I can install different images for emulators right so I can manage that from here all as well so that's why I like to install the Android Studio if you have the disk space to do this just install this it will make your life much easier so you can see this is installing so again we can just let this run and of course we need vs code right so I'm just going to search here for visual studio who would have thought like if you're old like me you know Microsoft and Linux it's like you know there weren't always friends now we are luckily and now we see Microsoft products here in this Linux App Store crazy crazy times so you can even go with the vs code insiders I'm just going to go with a regular one doesn't really matter which one you take again I'm going to click install enter my password and it's going to install vs code as well so okay this is running let's see my open jdk is is done here I'm actually not sure this is going off script here so if I type open jdk uh it's not doing anything but I'm pretty sure it installs and it uh actually maybe I need to do a new uh terminal as well open jdk to kind of like no that doesn't work okay so I'm just gonna trust that this works I'm pretty sure that I didn't need to do anything here that it sets up all the right paths and it will pick it up later so okay we got that um how do I check my progress on the Android studio and visual studio code I don't see code is installed okay so we should have Visual Studio code so if I scroll here we can see Visual Studio code I can just start that already and we have Android Studio already too not yet all right so let's just wait for that a little bit in the meantime Visual Studio code is coming up and we have all of this so we need some extra things in our key ring let's just my password again and here we are visual studio code on Linux how amazing is that so this is installed and here you of course have the terminal as well right we have the built-in terminal and if we go in here um can I zoom this in a little bit for you I can then you can here also see.net dash dash info it's going to give me the same thing right just all users the same stuff on your machine so this is all ready to go um now what I really would like to see is Android Studio coming up as well oh it's installed now I got a little notification at the top so it should be popping up here in my application overview anytime there we go Android studio and just start it and whenever you started it's going to ask you to import settings I don't have any settings to import um help improve no I'm not going to help you sorry for now and welcome right so here we have this Wizard who's going to walk you through getting the pre-requisites so next I'm just going to choose the standard installation which is fine choose a theme also fine because I'm not going to use this UI anyway and here's the things that it's going to install the Android emulator build tools for API 34 we'll get to that in a little bit the image system image for the emulator this all looks good so let's just do that you have to accept all the license agreements here and of course read them first I spent some time I was bored some editing reading through them of course you should too just accept them you can bulk accept them by clicking the root notes here except and then you can click next and it's going to do a couple of things here as well install for a while to get all this stuff on my machine so I'm going to do a very professional cut right here in the recording so you won't even notice it I promise and then it will all be done and we will pick up from there one eternity later and we're back okay so here you can see a little overview everything got installed we're all good here so let's just click finish and we can actually go into Android Studio it's being started for us more actions and you can see this SDK manager because what we want to do is actually install the target for API 33 at this point I think we're done at eight the default Target is going to be 34 but 4.7 is going to be 33 so we want to install that SDK as well and then for here for the tools I think everything is okay Android emulator I don't think we need to do anything here so let's just install this um sdk33 as well it's going to install couple of things is that all right yes that is and it's going to download some more things but in the meantime I can now maybe just for uh just to be sure let's restart Visual Studio code so that it picked up on all the new environment variables and that kind of stuff so here we have Visual Studio code and here we also have to install some stuff right so what we need to do is actually install the dotted Maui extension.net Maui we can just search for that and that will bring in all the stuff that we need so we have the c-sharp dev kit that it needs to bring in and some other things so we can get to this description page you can click install it starts installing you can read the description while we're doing that all great stuff so here it is um actually let's see if Android Studio is coming along this one's already done so we have sdk33 installed as well you can see actually the SDK path is home Gerald Android SDK so also that is installed in my home directory so let's just remember that I don't think uh we need that to set that manually I think it's picked up automatically but just to be sure we know where it is right now in case that we do need it manually if you check here under more actions what you can also do is have your virtual device manager right so you can have your Android emulators here so by default it installs this API 34 one and if I click Start and you can see that this doesn't work on my virtual machine but for you it just should start or you can start it whenever you start debugging your done and Maui project you can also edit it and edit all the properties right here or create a new one and create one according to your wishes so there's that but I'm going to use my physical device right actually while you're waiting for the done it Maui extension it takes a little while for some reason I can actually go over here to my physical Android device I can also um touch this touch this from my screen mirror here and go to settings and find the developer settings so where are those somewhere here probably developer options and here you have to turn all the developer options again I'm going to assume that you know how to do this for an Android device else just find it I think you have to tap on some Android version number a couple of times enable USB debugging right here and whenever you do that you can also enable wireless debugging so you can do wireless debugging so I'm just going to go in there it's already enabled and you can see that I can pair it and I can connect to it with this IP so I got all things set up here I think you first need to pair I'm not absolutely sure but I will show you how to do that in a minute and here you can see that it now installed the c-sharp dev kit I'm getting a welcome for that I'm going to close that one and I'm going to go to the welcome of this.net Maui extension the first thing I need to do is connect my account to c-sharp dev kit so let's click connect I have to connect my vs Visual Studio subscription here because this works with the same terms as like the full visual studio so you can definitely use it for free with Visual Studio commute Unity but also if you already of you we have a a visual studio subscription already or through your company log in with that account and you should be good to go for some reason it's not coming up here sign in so I'm just going to go to my notification here in the bottom right click sign in here and that does work so I'm going to click that it's going to bring up my browser I have to log in here with my credentials so I'm going to do that and of course I have two Vector authentication enabled so I need to log in here with my code as well don't bother trying this right now because this is pre-recorded I hate your virtual level this is not live so log in here through my device and that will bring me back hey you are signed in now you can close this window so I'm going to minimize this again and I'm back here in vs code and it locked me in the C sharp dev kit extension requires a pre-release version so for some reason it installs the wrong version I'm going to upgrade that that's going to run and now I lost my welcome to dotted Maui page can I actually get that back somehow Yes No Maybe um maybe if I restart Visual Studio code I will get the welcome screen again um you don't really of course need the welcome screen necessarily but it will take me through some steps uh to see if we got everything so here we get this welcome screen and here at the right you can see the the getting started for C sharp dev kit and the one for download Maui so let's click done and now we want set up your.net environment um so I'm pretty sure that I've got that set up already um done at dash dash version create new terminal dot net dash dash version so we got that right this shows a version so I'm going to assume this is all right actually this error right here um I got it I've seen bug reports for this already I'm not sure if this is some kind of configuration issue but you can ignore it it will still work so I'm not really sure what's going on but you can just ignore it just as this error acquiring.net maybe some path didn't get set up right but it will still work we'll see that in a little bit so you can ignore that for now or tell me in the comments how to fix it myself so I can get rid of these annoying messages set up your Maui environment so we did that as well I'm done workload install Maui which is not technically correct for Linux but we've seen that so we've already done that and then dot net workload list and you can see the install things and now we can actually start creating our DOT and Maui app so let's just do that click the button create new project all right let's do that and I can here create all kinds of apps so these are all apps that I can build on Linux as well but I'm going to go with the dotted Maui app it's going to ask me for a folder so let's create a new folder Maui test create open what should my Maui app be named like Maui app one let's just do that and now it's going to create my Maui app one project go to reload the visual studio code editor and it's going to ask me like hey do you trust the authors because some kind of security implications here yes I trust the author so I can run all the code in here again the error that we can ignore so let's just click that away and now it's activating the extensions so it's activating the net c-sharp dev kit it's installing the um spinning up the download Maui extension so we got all that and actually it says fail to restore solution done in Maui SDK not found okay interesting it's still okay so it has a couple of things Android SDK not found so I do need to do a couple of things here apparently so I need to do configure set up Android SDK path all right it actually picked it up automatically by just clicking that I think I'm done at Maui SDK not found learn more this is going to bring me to a browser I guess but I think I can just safely ignore this one because I'm pretty sure that you can definitely pick up my download Maui SDK so um let me just see if I can oh here we go let's just click this away and I'm just going to click away all the errors so one thing that you want to do is go to this Maui app one and into the Cs proj because what it's trying to do is it's going to try and build the iOS and Mac Catalyst here as well because this is the default template so what we want to do is kind of like duplicate this line then remove all of these from here and then kind of like mimic what we're doing for Windows here so we also want to have this condition but now for Linux and put it like this and put Linux in here and do not and then add this target Frameworks here in from as well so the way this works is in our CS project it's going to look for the Target Frameworks or Linux we can only do Android so that is something we can do on Windows on Mac OS and on Linux so that should always be there then we're going to have an additional Target Frameworks and we have a condition if it's not Linux because we can build iOS and Mac OS on Windows as well so if it's not Linux we can do we can get rid of the Android one here we can do iOS and Mac Catalyst in addition to the Target Frameworks that are already set because they are set right here and then another condition for Windows because we can only build Windows projects on a Windows machine so if the condition is Windows then we're going to take the existing Target Frameworks and we're going to add Windows to it as well so now we have it set up in a way that it works for all platforms let's just save that and I'm not sure it's going to reload and it's going to verify the environment so it's going to try and restore all the projects again and now it should actually work because it was trying to restore the packages for iOS and Mac OS as well which couldn't really work so now it should actually work here okay it keeps complaining about the Android SDK so let's configure set Android SDK path um let's actually then find it generals Android SDK open and now it should be able to find the Android SDK so I think that would put everything in place all right updates required okay I've seen that before um You probably can but you don't really have to so I'm going to ignore this for now let me know how to update it and if it's really necessary for you so what we can do now is go back to this Explorer right here and we can close this one and we can go to the solution Explorer so here this is the solution Explorer much more to your if you're used to visual studio full this behaves a little bit more like the solution Explorer there the example files and the Cs files were more close together you can see the dependencies and right click and manage nougat packages and all that kind of stuff so you can do all these kinds of things so here we have that and we can inspect our example we can inspect our code from here make changes this is at breakpoints and actually if I go to the build and run pane right here and run a debug and I click run and debug and click the.net Maui profile it should be able to build the project and it's going to start to run it or maybe it's just setting to build right now or it will start to trying to run it on the emulator which will won't work but at least we can verify that it builds right now so this all looks good it's progressing with building so that's really great The Next Step that we want to use actually run it on our physical device right so let's add the little plus sign here gives me a new terminal right here and what you want to do is uh CD dot dot in my case and CD I want to go to my home so I can do a dollar sign home as well that brings me to my home and then go to Android because the Android SDK hasn't been added to my path you can add the environment variable as well again if you've had this set up already that's totally fine let me see what the thing is here SDK and then I need to go into platform tools right whoops platform tools because what's in here is ADB and ADB is a tool for debugging Android debugging bridge I think and with ADB you can do all kinds of things one of which and typically this happens through the UI that's things that we do for you but now we're on Linux we do a little bit more ourselves right so we want to connect to our physical device and we can do ADB connect that's usually how you connect but we also have pair so let's do pair first and if I want to pair I went into my developer options here and there's one big gotcha here that got me a couple of times you can see the IP address and Port right here that's what you need for ADB connect in a little bit to actually connect to it but if you want to pair you click on this pair button right here and you will get this code but note that the IP address is the same but the port is different so that's what got me a couple of times okay so my Android project has been built but it says no debug Target available so skipping debugging that's fine but it did build success so let's go back to my terminal ADB pair a DB not ABD ADB pair and then I can put in my 192.168.1.59 four one nine eight one all right then let's go into ADB not found oh I need to dot slash okay well let's do this again dot slash it's going to execute it right now enter the code two five one seven o one enter and now it's successfully paired you can see it shows up it was already here but now it paired it's paired two times it should work two times as good but you can see it pairs automatically right so your device needs to be on the same Wi-Fi network as your machine and then it can find each other automatically so now I've got that set up and now I can do dot slash ADB connect and I can say 192.168.1.59 and then the port number here 33635 and now I can connect oh I added an extra dot in here can type under pressure and now it says connected and you can already see here so here in the bottom oh I'm actually in front of that so you can see that but here at the bottom you can see paired devices so it showed up in here and you can now see it says currently connected right so I'm currently connected to my physical machine right here and what's really cool if you go back to visual studio code it's not really that discoverable but here you have the curly braces and if you hover over that you can select your debug Target you can also pin it so it's in your status bar right here that makes it a little bit more visible and whenever you click that you can see the devices so I can see my emulator I can select that or I can now select my physical device that automatically showed up because I did that A to B connect so I can just click that or you can do control P which brings up the command palette in Visual Studio code do the angle bracket and search for Maui and you got a bunch of commands here as well right so you have pickup pick Android device and you can pick the same devices or get set up for development configure Android so you have a couple of things that will help you get this and now um you can see here still at the status bar that I have my Samsung device selected so if I do run and debug again it's going to again um build my project but now it's going to actually start a debug session on my physical device you can also do it on an emulator if you're running Linux on your physical machine right or if you're smarter than me and you can figure out the nested virtual machine stuff going on that's right here okay the project is built and now it's going to be deployed to my physical device um I can either you know touch through my mirrored screen right here or I can wake up my physical device right here and you can see it a little bit here in the camera view I can just touch it you can see whatever is happening there over on the screen so I can click it here as well we just have the default.in Maui template and I can go here through the code my c-sharp code I can set a breakpoint here I can click the button another time and it's going to hop over to my visual studio code I can skip over a line I can actually inspect all the parameter values right here so it's it's a little bit slow because this is on my VM and and this is going through Wi-Fi so it's all not really optimal but I promise you whenever you're going to do this in your environment it's much better so you can do all these things and now you know how to get set up with Linux developing.net Maui applications on your Linux device for Android this was a little bit of a longer video than you're used to for me but this is also a complete guide how to get started with.net development on your Linux machine and actually debugging it on a physical device so how amazing is that I hope you learned a lot let me know if you have any more questions or can figure things out let me know down in the comments and I will make some follow-up videos or give you some answers in there thank you so much for watching in one of my videos and if you want to know what this extension is actually all about you probably already know but maybe check out this video where I tell you all about it see you for the next one thank you
Info
Channel: Gerald Versluis
Views: 5,097
Rating: undefined out of 5
Keywords: .net maui, dotnet maui, .net maui tutorial, .net maui getting started, dotnet maui getting started, visual studio code, vs code, ubuntu, maui linux support, dotnet maui linux, c# maui linux, maui linux desktop, c# maui, dotnet maui vscode, dotnet maui mac, vscode maui, visual studio code tutorial, .net android, .net linux, dotnet sdk linux, install .net linux, setup dotnet linux, vscode linux, vscode linux install, vs code linux ubuntu, openjdk 11 install linux, android
Id: 4D2vUYUIqFU
Channel Id: undefined
Length: 34min 47sec (2087 seconds)
Published: Mon Jul 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.