Skip to content

Commit 57636c8

Browse files
[xaprepare] always delete ~/android-toolchain/dotnet (dotnet#6098)
I'm seeing failures on CI such as: C:\a\_work\2\s\build-tools\xaprepare\xaprepare\package-download.proj : warning MSB4242: The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed to run. Inconsistency in workload manifest 'microsoft.net.workload.mono.toolchain': missing dependency 'Microsoft.NET.Workload.Emscripten' C:\Users\cloudtest\android-toolchain\dotnet\sdk\6.0.100-preview.7.21369.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props(14,3): warning MSB4242: The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed to run. Inconsistency in workload manifest 'microsoft.net.workload.mono.toolchain': missing dependency 'Microsoft.NET.Workload.Emscripten' C:\Users\cloudtest\android-toolchain\dotnet\sdk\6.0.100-preview.7.21369.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.ImportWorkloads.props(14,38): error MSB4236: The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified could not be found. [C:\a\_work\2\s\build-tools\xaprepare\xaprepare\package-download.proj] Error: dotnet restore C:\a\_work\2\s\build-tools\xaprepare\xaprepare\package-download.proj failed. Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed System.InvalidOperationException: Step Xamarin.Android.Prepare.Step_InstallDotNetPreview failed at Xamarin.Android.Prepare.Scenario.<Run>d__26.MoveNext() in C:\a\_work\2\s\build-tools\xaprepare\xaprepare\Application\Scenario.cs:line 50 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.Android.Prepare.Context.<Execute>d__210.MoveNext() in C:\a\_work\2\s\build-tools\xaprepare\xaprepare\Application\Context.cs:line 827 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Xamarin.Android.Prepare.App.<Run>d__3.MoveNext() in C:\a\_work\2\s\build-tools\xaprepare\xaprepare\Main.cs:line 171 I saw the same thing locally, and noticed this folder was out of date: ~/android-toolchain/dotnet/sdk-manifests/6.0.100/microsoft.net.workload.mono.toolchain If we have an outdated `WorkloadManifest.json` or `WorkloadManifest.targets`, the build can get in a state where this step can't succeed. I manually deleted this folder to solve the problem: ~/android-toolchain/dotnet/ Going forward, let's make the `Prepare` step do this every time. This should simplify our .NET 6 provisioning & upgrade process.
1 parent 505b8e9 commit 57636c8

File tree

1 file changed

+2
-59
lines changed

1 file changed

+2
-59
lines changed

build-tools/xaprepare/xaprepare/Steps/Step_InstallDotNetPreview.cs

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,8 @@ protected override async Task<bool> Execute (Context context)
2121
var dotnetPreviewVersion = context.Properties.GetRequiredValue (KnownProperties.MicrosoftDotnetSdkInternalPackageVersion);
2222
var dotnetTestRuntimeVersion = Configurables.Defaults.DotNetTestRuntimeVersion;
2323

24-
// Delete any custom Microsoft.Android packs that may have been installed by test runs. Other ref/runtime packs will be ignored.
25-
var packsPath = Path.Combine (dotnetPath, "packs");
26-
if (Directory.Exists (packsPath)) {
27-
foreach (var packToRemove in Directory.EnumerateDirectories (packsPath)) {
28-
var info = new DirectoryInfo (packToRemove);
29-
if (info.Name.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) != -1) {
30-
Log.StatusLine ($"Removing Android pack: {packToRemove}");
31-
Utilities.DeleteDirectory (packToRemove);
32-
}
33-
}
34-
}
35-
36-
// Delete Workload manifests, such as sdk-manifests/6.0.100/Microsoft.NET.Sdk.Android
37-
var sdkManifestsPath = Path.Combine (dotnetPath, "sdk-manifests");
38-
if (Directory.Exists (sdkManifestsPath)) {
39-
foreach (var versionBand in Directory.EnumerateDirectories (sdkManifestsPath)) {
40-
foreach (var workloadManifestDirectory in Directory.EnumerateDirectories (versionBand)) {
41-
var info = new DirectoryInfo (workloadManifestDirectory);
42-
if (info.Name.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) != -1) {
43-
Log.StatusLine ($"Removing Android manifest directory: {workloadManifestDirectory}");
44-
Utilities.DeleteDirectory (workloadManifestDirectory);
45-
}
46-
}
47-
}
48-
}
49-
50-
// Delete any unnecessary SDKs if they exist.
51-
var sdkPath = Path.Combine (dotnetPath, "sdk");
52-
if (Directory.Exists (sdkPath)) {
53-
foreach (var sdkToRemove in Directory.EnumerateDirectories (sdkPath).Where (s => new DirectoryInfo (s).Name != dotnetPreviewVersion)) {
54-
Log.StatusLine ($"Removing out of date SDK: {sdkToRemove}");
55-
Utilities.DeleteDirectory (sdkToRemove);
56-
}
57-
}
58-
59-
// Delete Android template-packs
60-
var templatePacksPath = Path.Combine (dotnetPath, "template-packs");
61-
if (Directory.Exists (templatePacksPath)) {
62-
foreach (var templateToRemove in Directory.EnumerateFiles (templatePacksPath)) {
63-
var name = Path.GetFileName (templateToRemove);
64-
if (name.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) != -1) {
65-
Log.StatusLine ($"Removing Android template: {templateToRemove}");
66-
Utilities.DeleteFile (templateToRemove);
67-
}
68-
}
69-
}
70-
71-
// Delete the metadata folder, which contains old workload data
72-
var metadataPath = Path.Combine (dotnetPath, "metadata");
73-
if (Directory.Exists (metadataPath)) {
74-
Utilities.DeleteDirectory (metadataPath);
75-
}
76-
77-
if (File.Exists (dotnetTool)) {
78-
if (!TestDotNetSdk (dotnetTool)) {
79-
Log.WarningLine ($"Attempt to run `dotnet --version` failed, reinstalling the SDK.");
80-
Utilities.DeleteDirectory (dotnetPath);
81-
}
82-
}
24+
// Always delete the ~/android-toolchain/dotnet/ directory
25+
Utilities.DeleteDirectory (dotnetPath);
8326

8427
if (!await InstallDotNetAsync (context, dotnetPath, dotnetPreviewVersion)) {
8528
Log.ErrorLine ($"Installation of dotnet SDK {dotnetPreviewVersion} failed.");

0 commit comments

Comments
 (0)