From the course: .NET 9 Maui: Enhanced Features for Cross-Platform Development

Updating an existing project: Practical exercise

- [Instructor] The last topic we are going to look at is how to convert an existing project to .NET 9 MAUI. And the start code for this video is a new solution called Copilot.MAUI. This was a simple project that was an example for another course I wrote using .NET 8 MAUI. We are going to go through the process of converting it to .NET 9. There's not any automated process for doing this, and currently the best way is to manually edit a couple files. So I'm going to start with the Copilot.MAUI project file, and I'll right-click on it and go Edit Project File. And we're going to change the target frameworks to use .NET 9 instead of 8. And we'll do that for windows as well, and save it. And I also want to do that for this test project here. So I'll right click and go Edit Project File and change this from .NET 8 to .NET 9, and save that as well. Go back to Copilot.MAUI. And we're also going to want to make sure our iOS settings are correct, and we want the supported iOS platform to be 15, and also for macOS. So we're going to go down here, change this to 15, and maccatalyst, we're going to make it 15.0 as well, and save it. And the last thing we want to change is the app to use the new create window method. So we're going to open this up. And in App.xaml.cs, we're going to delete this where we say the MainPage is equal to the new AppShell, just like that. Instead, what we're going to do is add in the new CreateWindow method. So that'll be override and protected Window, and we'll make that CreateWindow. And that takes an IActivation state, and that's a nullable and activation state. And it's just going to return a new Window. And in the Window, we're going to pass in our AppShell. And save that. And that's the basics. And we're going to try running it. And we'll switch over to the iOS simulator here and we'll do it on iPhone 16, and press the Run button. All right, we have the application running. It wants to use the location, so we'll say while using the app. Get Location probably won't work 'cause we're in a simulator here. Theme Changer seems to work all right for us. So this application has been converted successfully from .NET 8 to .NET 9. You might have a slightly more complex situation. if you have things like bindings, you might want to update them to use compiled bindings. But for the most part, it's pretty simple to get .NET 8 application for MAUI running on .NET 9.

Contents