Skip to content

Commit 0fa9460

Browse files
authored
Update Maui runs to get NuGet.config and Version.Details.xml from maui repo (#5056)
Update Maui runs to use Maui repos NuGet.config and Version.Details.xml (<- only when installing versioned, which we currently do not do) to help minimize downtime due to Maui taking a version of packages we don't have in the performance NuGet.config.
1 parent 23c58db commit 0fa9460

File tree

8 files changed

+325
-136
lines changed

8 files changed

+325
-136
lines changed

src/scenarios/mauiandroid/pre.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from performance.logger import setup_loggers, getLogger
77
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
99
from shared.precommands import PreCommands
1010
from shared.versionmanager import versions_write_json, get_sdk_versions
1111
from test import EXENAME
@@ -19,16 +19,20 @@
1919
install_latest_maui(precommands)
2020
precommands.print_dotnet_info()
2121

22-
# Setup the Maui folder
23-
precommands.new(template='maui',
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-
# Build the APK
31-
precommands.execute([])
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',
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+
# Build the APK - will also use merged NuGet.config
34+
precommands.execute([])
35+
# NuGet.config is automatically restored after this block
3236

3337
# Remove the aab files as we don't need them, this saves space
3438
output_dir = const.PUBDIR

src/scenarios/mauiblazorandroid/pre.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from performance.logger import setup_loggers, getLogger
77
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
99
from shared.precommands import PreCommands
1010
from shared.versionmanager import versions_write_json, get_sdk_versions
1111
from test import EXENAME
@@ -19,17 +19,20 @@
1919
install_latest_maui(precommands)
2020
precommands.print_dotnet_info()
2121

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(
3336
'''
3437
@code {
3538
protected override void OnAfterRender(bool firstRender)
@@ -42,24 +45,25 @@
4245
}
4346
}
4447
''')
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;")
4552

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
6367

6468
output_dir = const.PUBDIR
6569
if precommands.output:

src/scenarios/mauiblazordesktop/pre.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@
99
from shared.codefixes import insert_after
1010
from shared.precommands import PreCommands
1111
from shared import const
12+
from shared.mauisharedpython import install_latest_maui, MauiNuGetConfigContext
1213
from test import EXENAME
13-
import requests
1414

1515
setup_loggers(True)
16-
17-
NugetURL = 'https://raw.githubusercontent.com/dotnet/maui/net7.0/NuGet.config'
18-
NugetFile = requests.get(NugetURL)
19-
open('./Nuget.config', 'wb').write(NugetFile.content)
16+
logger = getLogger(__name__)
2017

2118
precommands = PreCommands()
22-
precommands.install_workload('maui', ['--from-rollback-file', 'https://aka.ms/dotnet/maui/net7.0.json', '--configfile', './Nuget.config'])
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)
2919

30-
shutil.copy2(os.path.join(const.SRCDIR, 'Replacement.Index.razor.cs'), os.path.join(const.APPDIR, 'Pages', 'Index.razor.cs'))
31-
precommands.add_startup_logging(os.path.join('Pages', 'Index.razor.cs'), "if (firstRender) {")
32-
precommands.execute(['/p:Platform=x64','/p:WindowsAppSDKSelfContained=True','/p:WindowsPackageType=None','/p:WinUISDKReferences=False','/p:PublishReadyToRun=true'])
20+
install_latest_maui(precommands)
21+
precommands.print_dotnet_info()
22+
23+
# Use context manager to temporarily merge MAUI's NuGet feeds into repo config
24+
# This ensures both dotnet new and dotnet build/publish have access to MAUI packages
25+
with MauiNuGetConfigContext(precommands.framework):
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+
shutil.copy2(os.path.join(const.SRCDIR, 'Replacement.Index.razor.cs'), os.path.join(const.APPDIR, 'Pages', 'Index.razor.cs'))
34+
precommands.add_startup_logging(os.path.join('Pages', 'Index.razor.cs'), "if (firstRender) {")
35+
precommands.execute(['/p:Platform=x64','/p:WindowsAppSDKSelfContained=True','/p:WindowsPackageType=None','/p:WinUISDKReferences=False','/p:PublishReadyToRun=true'])
36+
# NuGet.config is automatically restored after this block

src/scenarios/mauiblazorios/pre.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,32 @@
55
import sys
66
from performance.logger import setup_loggers, getLogger
77
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
99
from shared.precommands import PreCommands
1010
from shared.versionmanager import versions_write_json, get_sdk_versions
1111
from test import EXENAME
1212

1313
setup_loggers(True)
14+
logger = getLogger(__name__)
15+
1416
precommands = PreCommands()
1517
install_latest_maui(precommands)
1618
precommands.print_dotnet_info()
1719

18-
# Setup the Maui folder
19-
precommands.new(template='maui-blazor',
20-
output_dir=const.APPDIR,
21-
bin_dir=const.BINDIR,
22-
exename=EXENAME,
23-
working_directory=sys.path[0],
24-
no_restore=False)
25-
26-
# Update the home.razor file with the code
27-
with open(f"{const.APPDIR}/Components/Pages/Home.razor", "a") as homeRazorFile:
28-
homeRazorFile.write(
20+
# Use context manager to temporarily merge MAUI's NuGet feeds into repo config
21+
# This ensures both dotnet new and dotnet build/publish have access to MAUI packages
22+
with MauiNuGetConfigContext(precommands.framework):
23+
# Setup the Maui folder - will use merged NuGet.config with MAUI feeds
24+
precommands.new(template='maui-blazor',
25+
output_dir=const.APPDIR,
26+
bin_dir=const.BINDIR,
27+
exename=EXENAME,
28+
working_directory=sys.path[0],
29+
no_restore=False)
30+
31+
# Update the home.razor file with the code
32+
with open(f"{const.APPDIR}/Components/Pages/Home.razor", "a") as homeRazorFile:
33+
homeRazorFile.write(
2934
'''
3035
@code {
3136
protected override void OnAfterRender(bool firstRender)
@@ -37,10 +42,10 @@
3742
}
3843
}
3944
''')
40-
41-
# Build the IPA
42-
# NuGet.config file cannot be in the build directory due same cause as to https://github.com/dotnet/aspnetcore/issues/41397
43-
precommands.execute(['/p:EnableCodeSigning=false', '/p:ApplicationId=net.dot.mauiblazortesting'])
45+
46+
# Build the IPA - will use merged NuGet.config
47+
precommands.execute(['/p:EnableCodeSigning=false', '/p:ApplicationId=net.dot.mauiblazortesting'])
48+
# NuGet.config is automatically restored after this block
4449

4550
output_dir = const.PUBDIR
4651
if precommands.output:

src/scenarios/mauidesktop/pre.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@
55
import subprocess
66
import sys
77
import os
8-
from performance.logger import setup_loggers
8+
from performance.logger import setup_loggers, getLogger
99
from shared.precommands import PreCommands
1010
from shared import const
11+
from shared.mauisharedpython import install_latest_maui, MauiNuGetConfigContext
1112
from test import EXENAME
12-
import requests
1313

1414
setup_loggers(True)
15-
NugetURL = 'https://raw.githubusercontent.com/dotnet/maui/main/NuGet.config'
16-
NugetFile = requests.get(NugetURL)
17-
open('./Nuget.config', 'wb').write(NugetFile.content)
15+
logger = getLogger(__name__)
1816

1917
precommands = PreCommands()
20-
precommands.install_workload('maui', ['--from-rollback-file', 'https://aka.ms/dotnet/maui/net7.0.json', '--configfile', './Nuget.config'])
21-
precommands.new(template='maui',
22-
output_dir=const.APPDIR,
23-
bin_dir=const.BINDIR,
24-
exename=EXENAME,
25-
working_directory=sys.path[0],
26-
no_restore=False)
2718

28-
precommands.execute(['/p:Platform=x64','/p:WindowsAppSDKSelfContained=True','/p:WindowsPackageType=None','/p:WinUISDKReferences=False','/p:PublishReadyToRun=true'])
19+
install_latest_maui(precommands)
20+
precommands.print_dotnet_info()
21+
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+
precommands.new(template='maui',
26+
output_dir=const.APPDIR,
27+
bin_dir=const.BINDIR,
28+
exename=EXENAME,
29+
working_directory=sys.path[0],
30+
no_restore=False)
31+
32+
precommands.execute(['/p:Platform=x64','/p:WindowsAppSDKSelfContained=True','/p:WindowsPackageType=None','/p:WinUISDKReferences=False','/p:PublishReadyToRun=true'])
33+
# NuGet.config is automatically restored after this block

src/scenarios/mauiios/pre.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import subprocess
77
from performance.logger import setup_loggers, getLogger
88
from shared import const
9-
from shared.mauisharedpython import remove_aab_files, install_latest_maui
9+
from shared.mauisharedpython import remove_aab_files, install_latest_maui, MauiNuGetConfigContext
1010
from shared.precommands import PreCommands
1111
from shared.versionmanager import versions_write_json, get_sdk_versions
1212
from test import EXENAME
@@ -17,16 +17,20 @@
1717
install_latest_maui(precommands)
1818
precommands.print_dotnet_info()
1919

20-
# Setup the Maui folder
21-
precommands.new(template='maui',
22-
output_dir=const.APPDIR,
23-
bin_dir=const.BINDIR,
24-
exename=EXENAME,
25-
working_directory=sys.path[0],
26-
no_restore=False)
27-
28-
# Build the APK
29-
precommands.execute(['/p:EnableCodeSigning=false', '/p:ApplicationId=net.dot.mauitesting'])
20+
# Use context manager to temporarily merge MAUI's NuGet feeds into repo config
21+
# This ensures both dotnet new and dotnet build/publish have access to MAUI packages
22+
with MauiNuGetConfigContext(precommands.framework):
23+
# Setup the Maui folder - will use merged NuGet.config with MAUI feeds
24+
precommands.new(template='maui',
25+
output_dir=const.APPDIR,
26+
bin_dir=const.BINDIR,
27+
exename=EXENAME,
28+
working_directory=sys.path[0],
29+
no_restore=False)
30+
31+
# Build the IPA - will also use merged NuGet.config
32+
precommands.execute(['/p:EnableCodeSigning=false', '/p:ApplicationId=net.dot.mauitesting'])
33+
# NuGet.config is automatically restored after this block
3034

3135
# Remove the aab files as we don't need them, this saves space
3236
output_dir = const.PUBDIR

src/scenarios/mauisamplecontentandroid/pre.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from performance.logger import setup_loggers, getLogger
77
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
99
from shared.precommands import PreCommands
1010
from shared.versionmanager import versions_write_json, get_sdk_versions
1111
from test import EXENAME
@@ -19,17 +19,21 @@
1919
install_latest_maui(precommands)
2020
precommands.print_dotnet_info()
2121

22-
# Setup the Maui folder
23-
precommands.new(template='maui',
24-
output_dir=const.APPDIR,
25-
bin_dir=const.BINDIR,
26-
exename=EXENAME,
27-
working_directory=sys.path[0],
28-
no_restore=False,
29-
extra_args=['--sample-content'])
30-
31-
# Build the APK
32-
precommands.execute([])
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',
27+
output_dir=const.APPDIR,
28+
bin_dir=const.BINDIR,
29+
exename=EXENAME,
30+
working_directory=sys.path[0],
31+
no_restore=False,
32+
extra_args=['--sample-content'])
33+
34+
# Build the APK - will use merged NuGet.config
35+
precommands.execute([])
36+
# NuGet.config is automatically restored after this block
3337

3438
# Remove the aab files as we don't need them, this saves space
3539
output_dir = const.PUBDIR

0 commit comments

Comments
 (0)