当前位置:网站首页>(01). Net Maui actual construction project

(01). Net Maui actual construction project

2022-06-13 00:46:00 Dotnet cross platform

1. Summary

This series of articles will address .NET MAUI Some contents of actual development , I will continuously update what I have learned for a long time . When learning new software development techniques , Will start with infrastructure projects MAUI No exception .

ref:https://docs.microsoft.com/zh-cn/dotnet/maui/get-started/first-app?pivots=devices-windows

This article will share the following :

  • 1.VS Version selection for ( This content is too simple to handle directly )

  • 2. Build project ( This content is too simple to handle directly )

  • 3. understand MAUI Project structure ( Key content )

  • 4.DEBUG Catalog

2. The detailed content

(1)VS Version selection

At present, this article uses a preview version of visual studio 2022, The official version will be gradually improved MAUI Project template creation .

Download address :https://c2rsetup.officeapps.live.com/c2r/downloadVS.aspx?sku=Community&channel=Preview&Version=VS2022&source=VSLandingPage&add=Microsoft.VisualStudio.Workload.CoreEditor&add=Microsoft.VisualStudio.Workload.NetCrossPlat;includeRecommended&cid=2302

install Visual Studio Or modify the installation , And install... Using the default optional installation options .NET Multi-platform application UI Development workload :

a97c8bb51385983ae074b32a2ffd1d66.png

(2) Construction project

start-up Visual Studio 2022 17.3 preview , Then click... In the start window “ Create a new project ” To create a new project :

d1874d9c5aa2864bd5d3d7609a531141.png

stay “ Create a new project ” Window , choice “ All project types ” In the drop-down list MAUI, choice .NET MAUI application Templates , And then click “ next step ” Button :

7864071befdd0222bb3f23f90eefc1e7.png

stay “ Configure new projects ” Window , Name the project , Choose the right location for it , And then click “ establish ” Button :

92644ad3361fc772083d197afba7c272.png

Wait for the project to be created and its dependencies restored :

ad07adb1d297ea2f52f0d127a7f9a66d.png

stay Visual Studio In the toolbar , Use “ Debugging objectives ” Drop down list selection frame , And then choose net6.0-windows entry ( What needs to be specified here is the selection windows The platform can avoid installing simulators ):

81c65491cfb5c95a61e3064dbbb94048.png

stay Visual Studio In the toolbar , Press Windows Computer Button to generate and run the application :

bf4ef6043cb246f763c25549318e733f.png

If developer mode is not enabled ,Visual Studio You will be prompted to enable it . stay “ by Windows Enable Developer mode ” In the dialog box , single click Developer settings To open the settings application :

49b2212184cd323b1f0c2ce3cd0ed0ed.png

In the settings app , open Developer mode And accept the disclaimer :

0ab37d10d309817b9445122d1c4fe672.png

Close the settings application , Then close it “ by Windows Enable Developer mode ” Dialog box .

In a running application , Multiple press “ Click me ” Button , And watch the count of button clicks increase :

5c04bb42a8840506a36fa80ec233b893.png

(3) Interpretation of project structure

  • rely on

1e11dd0d9592ca3e005898d0d8532d02.png

open MAUI The project structure is red “ rely on ” when , Can see 4 References to platforms , Android 、 Apple 、windows、mac. as for linux The platform needs to know the project address :https://github.com/jsuarezruiz/maui-linux be based on GtkSharp add to Linux Support .

  • Platforms

a347609e24762525f01e93292ab948ad.png

Main program classes for different platforms . In the latest release, it is worth mentioning that , In the picture above we can see Tizen Update . Let's see Tizen What is it? ?

a865601ff6c4473bdd1420e37c2df6ab.png

3fa50342bebffd2d6b8fed1bfd9a52c7.png

In this update, you can see the update of this platform , in the future MAUI It is likely to be used in the on-board system . If it can be applied in this way , It has to be said that Microsoft is not prepared to leave opportunities for other technologies . In the future, I will continue to pay attention to whether this line is really so .

  • Resources

f1fc525eb6cca5150ebdde025b180e32.png

The meaning of this folder is very obvious. I won't explain it one by one , This point is for novice developers . Undoubtedly, some coding specifications have been formulated , The resources of are stored in the corresponding folder for centralized management .

  • xaml

9fbe928a5e61a5c1e20f22eb889060c7.png

app.xaml , This is the setup MAUI The default startup form and other operations , The usage here will be explained in subsequent articles .

577cdf9bd71e67721be7fc2d523d5090.png

MainPage.xaml It's like wpf Of mainwindo 了 , Write form code , Layout control .

3ea6b655829e74075628072135fce286.png

MauiProgram.cs It's very similar here asp.net The start of class , You can add injection components or set Fonts 、 Contents of platform configuration .

ef406a59d1b775ca4fc174e8bab4f7b1.png

Here you can see , It can be used #if To determine which corresponding configurations the current platform should start . The usage here is also important .

(4)Debug Catalog

982fd9f14fa5b9d6f037fef7e69797fb.png

When our program is finished , Can be in debug See the files of the corresponding platform under the directory . It should be noted here that only the version folder corresponding to the compilation can contain content . The following articles will tell you how to compile and formulate the platform version through commands . Here I use windows For example, the platform can directly see the executable file .

8bbb8336caa3e4360e13a8b1c67f3ee9.png

When we F5 Have run MAUI After that, you can also “win” You can see the startup shortcut in the Startup menu of .

945bc34e3be3a75f7e6706c26b485acf.png

I hope you will pay more attention to my wechat official account and b Station account will update video and articles . Thank you for watching .

原网站

版权声明
本文为[Dotnet cross platform]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130036473770.html