Skip to content

Commit 6b00188

Browse files
[build-tools] fix InstallMaui target for .NET 7 (#7173)
This addresses several problems with the `InstallMaui` target: 1. There was not a way to override `$(MauiVersionBand)`. You can now pass this value in such as `-p:MauiVersionBand=7.0.100`. 2. The logic for computing `$(MauiVersionBand)` was wrong: error NU1101: Unable to find package Microsoft.NET.Sdk.Maui.Manifest-7.0.000. This should default to `$(DotNetSdkManifestsFolder)` now, which will work by default when this lands: dotnet/maui#8737 Until dotnet/maui#8737 is merged, `-p:MauiVersionBand=7.0.100` can be used. 3. The `dotnet6` feed is now required: Workload installation failed: microsoft.maui.sdk::6.0.408 is not found in NuGet feeds https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json;https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json;https://pkgs.dev.azure.com/xamarin/public/_packaging/Xamarin.Android/nuget/v3/index.json". This is a .NET 6 package on NuGet.org, but not in dotnet-public. It is necessary when building `net6.0-*` MAUI projects with a .NET 7 SDK. I added logic to parse the `NuGet.config` file and add an extra source for the `dotnet6` feed. This should be the most reliable method going forward.
1 parent 60f787a commit 6b00188

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

build-tools/scripts/DotNet.targets

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<Error Text="%24(MauiVersion) must be specified." Condition=" '$(MauiVersion)' == '' " />
4747
<PropertyGroup>
4848
<_TempDirectory>$(DotNetPreviewPath)..\.xa-workload-temp-$([System.IO.Path]::GetRandomFileName())</_TempDirectory>
49-
<MauiVersionBand>$([System.Text.RegularExpressions.Regex]::Match($(MauiVersion), `^\d+\.\d+\.\d`))00</MauiVersionBand>
49+
<MauiVersionBand Condition=" '$(MauiVersionBand)' == '' ">$(DotNetSdkManifestsFolder)</MauiVersionBand>
5050
</PropertyGroup>
5151
<MakeDir Directories="$(_TempDirectory)" />
5252
<Exec
@@ -61,11 +61,19 @@
6161
</ItemGroup>
6262
<Copy SourceFiles="@(_WLManifest)" DestinationFolder="$(DotNetPreviewPath)sdk-manifests\$(DotNetSdkManifestsFolder)\microsoft.net.sdk.maui" />
6363

64+
<!-- Parse NuGet.config -->
65+
<XmlPeek
66+
XmlInputPath="$(XamarinAndroidSourcePath)NuGet.config"
67+
Query="/configuration/packageSources/add/@value">
68+
<Output TaskParameter="Result" ItemName="_NuGetSources" />
69+
</XmlPeek>
70+
6471
<!-- dotnet workload install maui-android -->
6572
<ItemGroup>
73+
<_NuGetSources Include="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
6674
<_InstallArguments Include="--skip-manifest-update" />
6775
<_InstallArguments Include="--verbosity diag" />
68-
<_InstallArguments Include="--configfile &quot;$(XamarinAndroidSourcePath)NuGet.config&quot;" />
76+
<_InstallArguments Include="--source &quot;%(_NuGetSources.Identity)&quot;" />
6977
<_InstallArguments Include="--temp-dir &quot;$(_TempDirectory)&quot;" />
7078
</ItemGroup>
7179
<Exec

0 commit comments

Comments
 (0)