Skip to content

Commit 59a2630

Browse files
Workaround MVIDs from dotnet/linker
Context: dotnet/runtime#45649 Context: dotnet/linker#2203 We are getting unique MVIDs per architecture output from the linker. To workaround this problem, I used the "size" of the files instead. This works for now, but is not 100% correct. I think it would be fine for .NET 7 Android apps to use this for now in main. (hopefully temporary)
1 parent f1ead79 commit 59a2630

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,16 @@ void DeduplicateAssemblies (List<ITaskItem> output, Dictionary<string, ITaskItem
122122
{
123123
// Group by assembly file name
124124
foreach (var group in InputAssemblies.Where (Filter).GroupBy (a => Path.GetFileName (a.ItemSpec))) {
125-
// Get the unique list of MVIDs
126-
var mvids = new HashSet<Guid> ();
125+
// HACK: Use file size instead of MVID, revert this later!
126+
// see: https://github.com/dotnet/runtime/issues/45649
127+
// see: https://github.com/dotnet/linker/issues/2203
128+
var fileSizes = new HashSet<long> ();
127129
bool? frameworkAssembly = null, hasMonoAndroidReference = null;
128130
foreach (var assembly in group) {
129-
using var pe = new PEReader (File.OpenRead (assembly.ItemSpec));
131+
using var stream = File.OpenRead (assembly.ItemSpec);
132+
using var pe = new PEReader (stream);
130133
var reader = pe.GetMetadataReader ();
131-
var module = reader.GetModuleDefinition ();
132-
var mvid = reader.GetGuid (module.Mvid);
133-
mvids.Add (mvid);
134+
fileSizes.Add (stream.Length);
134135

135136
// Calculate %(FrameworkAssembly) and %(HasMonoAndroidReference) for the first
136137
if (frameworkAssembly == null) {
@@ -144,7 +145,7 @@ void DeduplicateAssemblies (List<ITaskItem> output, Dictionary<string, ITaskItem
144145
assembly.SetMetadata ("HasMonoAndroidReference", hasMonoAndroidReference.ToString ());
145146
}
146147
// If we end up with more than 1 unique mvid, we need *all* assemblies
147-
if (mvids.Count > 1) {
148+
if (fileSizes.Count > 1) {
148149
foreach (var assembly in group) {
149150
var symbol = GetOrCreateSymbolItem (symbols, assembly);
150151
SetDestinationSubDirectory (assembly, group.Key, symbol, isDuplicate: true);

0 commit comments

Comments
 (0)