|
5 | 5 | import sys |
6 | 6 | from performance.logger import setup_loggers, getLogger |
7 | 7 | from shared import const |
8 | | -from shared.mauisharedpython import remove_aab_files, install_latest_maui |
| 8 | +from shared.mauisharedpython import remove_aab_files, install_latest_maui, MauiNuGetConfigContext |
9 | 9 | from shared.precommands import PreCommands |
10 | 10 | from shared.versionmanager import versions_write_json, get_sdk_versions |
11 | 11 | from test import EXENAME |
|
19 | 19 | install_latest_maui(precommands) |
20 | 20 | precommands.print_dotnet_info() |
21 | 21 |
|
22 | | -# Setup the Maui folder |
23 | | -precommands.new(template='maui-blazor', |
24 | | - output_dir=const.APPDIR, |
25 | | - bin_dir=const.BINDIR, |
26 | | - exename=EXENAME, |
27 | | - working_directory=sys.path[0], |
28 | | - no_restore=False) |
29 | | - |
30 | | -# Update the home.razor file with the code |
31 | | -with open(f"{const.APPDIR}/Components/Pages/Home.razor", "a") as homeRazorFile: |
32 | | - homeRazorFile.write( |
| 22 | +# Use context manager to temporarily merge MAUI's NuGet feeds into repo config |
| 23 | +# This ensures both dotnet new and dotnet build/publish have access to MAUI packages |
| 24 | +with MauiNuGetConfigContext(precommands.framework): |
| 25 | + # Setup the Maui folder - will use merged NuGet.config with MAUI feeds |
| 26 | + precommands.new(template='maui-blazor', |
| 27 | + output_dir=const.APPDIR, |
| 28 | + bin_dir=const.BINDIR, |
| 29 | + exename=EXENAME, |
| 30 | + working_directory=sys.path[0], |
| 31 | + no_restore=False) |
| 32 | + |
| 33 | + # Update the home.razor file with the code |
| 34 | + with open(f"{const.APPDIR}/Components/Pages/Home.razor", "a") as homeRazorFile: |
| 35 | + homeRazorFile.write( |
33 | 36 | ''' |
34 | 37 | @code { |
35 | 38 | protected override void OnAfterRender(bool firstRender) |
|
42 | 45 | } |
43 | 46 | } |
44 | 47 | ''') |
| 48 | + |
| 49 | + # Open the _Imports.razor file for appending |
| 50 | + with open(f"{const.APPDIR}/_Imports.razor", "a") as importsFile: |
| 51 | + importsFile.write("@using Android.App;") |
45 | 52 |
|
46 | | -# Open the _Imports.razor file for appending |
47 | | -with open(f"{const.APPDIR}/_Imports.razor", "a") as importsFile: |
48 | | - importsFile.write("@using Android.App;") |
49 | | - |
50 | | -# Replace line in the Android MainActivity.cs file |
51 | | -with open(f"{const.APPDIR}/Platforms/Android/MainActivity.cs", "r") as mainActivityFile: |
52 | | - mainActivityFileLines = mainActivityFile.readlines() |
53 | | - |
54 | | -with open(f"{const.APPDIR}/Platforms/Android/MainActivity.cs", "w") as mainActivityFile: |
55 | | - for line in mainActivityFileLines: |
56 | | - if line.startswith("{"): |
57 | | - mainActivityFile.write("{\npublic static Android.Content.Context Context { get; private set; }\npublic MainActivity() { Context = this; }") |
58 | | - else: |
59 | | - mainActivityFile.write(line) |
60 | | - |
61 | | -# Build the APK |
62 | | -precommands.execute([]) |
| 53 | + # Replace line in the Android MainActivity.cs file |
| 54 | + with open(f"{const.APPDIR}/Platforms/Android/MainActivity.cs", "r") as mainActivityFile: |
| 55 | + mainActivityFileLines = mainActivityFile.readlines() |
| 56 | + |
| 57 | + with open(f"{const.APPDIR}/Platforms/Android/MainActivity.cs", "w") as mainActivityFile: |
| 58 | + for line in mainActivityFileLines: |
| 59 | + if line.startswith("{"): |
| 60 | + mainActivityFile.write("{\npublic static Android.Content.Context Context { get; private set; }\npublic MainActivity() { Context = this; }") |
| 61 | + else: |
| 62 | + mainActivityFile.write(line) |
| 63 | + |
| 64 | + # Build the APK - will use merged NuGet.config |
| 65 | + precommands.execute([]) |
| 66 | +# NuGet.config is automatically restored after this block |
63 | 67 |
|
64 | 68 | output_dir = const.PUBDIR |
65 | 69 | if precommands.output: |
|
0 commit comments