Home > Blockchain >  Using Visual Basic.Net along with .Net Maui Application
Using Visual Basic.Net along with .Net Maui Application

Time:08-11

Today was an official full release .Net Maui for Visual Studio 2022. A few years ago I used Visual Basic as a PCL project along with a minimal C# Xamarin project to create a mobile application for Android & iOS. Today I've decided to test the same method with .Net Maui to develop a cross platform application. I successfully combined the two together using similar steps. These steps should get you started to make a basic solution allowing you to use a VB class module to programmatically create controls and insert them into a form then display the results.

  1. Create a .Net MAUI Class Library project [Picture][1]

  2. Name your project and choose a location. [Picture][2]

  3. Click Create. [Picture][3]

  4. Close project. [Picture][4]

  5. Open File Explorer and go to the .Net Maui Class Project

  6. Delete bin & obj folders

  7. Delete Solution file

  8. Rename Class1.cs to Class1.vb

  9. Rename MauiLibTest.csproj to MauiLibTest.vbproj

  10. Rename all sub folders PlatformClass1.cs to PlatformClass1.vb [Picture][5]

  11. Open each renamed class vb file in notepad and convert code from C# to Visual Basic Converters you can use:

    Online: https://converter.telerik.com/
    Application: Instant VB https://www.tangiblesoftwaresolutions.com/
    

[Example Picture of Class1 before conversion][6]

[Example Picture of Class1 after conversion][7]

  1. Convert each of the C# code in PlatformClass1.vb in each sub folder.

[Example Picture of PlatformClass1 before conversion][8]

[Example Picture of PlatformClass1 before conversion][9]

  1. Open the .Net Maui Class Library project file.
  2. There are 2 files missing. They will need to be created.
  • C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.446-ci.-release-6-0-4xx.446\tools\msbuild\iOS\Xamarin.iOS.VB.targets
  • C:\Program Files\dotnet\packs\Microsoft.MacCatalyst.Sdk\15.4.446-ci.-release-6-0-4xx.446\tools\msbuild\MacCatalyst\Xamarin.MacCatalyst.VB.targets

[Picture of project with missing files.][10]

  1. Open File Explorer to:
  • C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.446-ci.-release-6-0-4xx.446\tools\msbuild\iOS\
  1. Copy Xamarin.iOS.CSharp.targets and paste in folder and rename to Xamarin.iOS.VB.targets [Picture][11]
  2. Open Xamarin.iOS.VB.targets in Notepad and change all text Microsoft.CSharp.targets to Microsoft.VB.targets
  3. Save File to another location due to security and copy that file back to the original folder.

19: Open File Explorer to: - C:\Program Files\dotnet\packs\Microsoft.MacCatalyst.Sdk\15.4.446-ci.-release-6-0-4xx.446\tools\msbuild\MacCatalyst 20: Copy Xamarin.MacCatalyst.CSharp.targets and paste in folder and rename to Xamarin.MacCatalyst.VB.targets [Picture][12]

  1. Open Xamarin.MacCatalyst.VB.targets in Notepad and change Microsoft.CSharp.targets to Microsoft.VB.targets

  2. Save File to another location due to security and copy that file back to the original folder.

  3. Go back to Visual Studio the 2 error messages are gone. [Picture][13]

  4. Compile to make sure that project is ok.

  5. Close Visual Studio

  6. Create new .Net Maui App [Picture][14]

  7. Select the same parent folder location as the .Net Maui Class Library project. [Picture][15]

  8. Click Create

  9. Project will open. [Picture][16]

  10. Delete these these files: AppShel.xaml, MainPage.xaml

  11. Right click Solution > Add > Existing Project [Picture][17]

  12. Select the Maui Class Library Project that was converted into Visual Basic [Picture][18]

  13. Rename Class.vb in the Maui Class Project to Start.vb [Picture before renaming.][19] [Picture after renaming.][20]

  14. Add the line Imports Microsoft.Maui.Controls to top of class module

  15. Add the line Inherits ContentPage under Public Class Start [Picture after inserted lines.][21]

  16. Right click Dependencies under Maui App Project and click Add Project Reference... [Look right side of image for example of Adding Reference][22]

  17. Check the Maui Class Library Project and click Ok. [Picture][23]

  18. Under App.xaml.cs in .Net Maui App project comment out MainPage = new AppShell();

  19. Add line: MainPage = new ..Start(); For example: MainPage = new MauiLibTest.MauiLibTest.Start(); [Picture after lines changed.][24]

  20. Under Start.vb add a public subroutine called New.

  21. From this point create module level controls of your choosing.

  22. At the end of adding your controls set the content: Me.Content =

    • For example: Me.Content = scvTest

[Picture of added code to Start.vb class module][25]

  1. Compile and run project. You should have the Hello World app running. [Picture of running application.][26]

From here you can:

  • Edit the MauiProgram.cs file for additional fonts.
  • Add more files to your Resources folder.
  • Add additional classes to your .Net Maui Class project as other pages.

I will keep playing and see what else I can do. Good luck and have fun.

CodePudding user response:

Links to pictures above:
[1]: https://i.stack.imgur.com/J56FI.png [2]: https://i.stack.imgur.com/bOnGt.png [3]: https://i.stack.imgur.com/7HbyM.png [4]: https://i.stack.imgur.com/ChHGH.png [5]: https://i.stack.imgur.com/wKLrc.png [6]: https://i.stack.imgur.com/naRIa.png [7]: https://i.stack.imgur.com/XjVa6.png [8]: https://i.stack.imgur.com/EBQfD.png

CodePudding user response:

2nd Links: [9]: https://i.stack.imgur.com/idAvf.png [10]: https://i.stack.imgur.com/tYfGc.png [11]: https://i.stack.imgur.com/7zIOj.png [12]: https://i.stack.imgur.com/XyIZj.png [13]: https://i.stack.imgur.com/YSfj5.png [14]: https://i.stack.imgur.com/dy6tz.png [15]: https://i.stack.imgur.com/8d0cx.png [16]: https://i.stack.imgur.com/hLdno.png

CodePudding user response:

3rd Section of pictures: [17]: https://i.stack.imgur.com/CfsdM.png [18]: https://i.stack.imgur.com/hWf53.png [19]: https://i.stack.imgur.com/qzvlP.png [20]: https://i.stack.imgur.com/wMxIq.png [21]: https://i.stack.imgur.com/Rx8h7.png [22]: https://i.stack.imgur.com/d21dc.png [23]: https://i.stack.imgur.com/q2zmm.png [24]: https://i.stack.imgur.com/psFJj.png

  • Related