Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,16 @@ void AddEnvironment ()
HashSet<string> archAssemblyNames = null;
HashSet<string> uniqueAssemblyNames = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
Action<ITaskItem> updateAssemblyCount = (ITaskItem assembly) => {
// We need to use the 'RelativePath' metadata, if found, because it will give us the correct path for satellite assemblies - with the culture in the path.
string? relativePath = assembly.GetMetadata ("RelativePath");
string assemblyName = String.IsNullOrEmpty (relativePath) ? Path.GetFileName (assembly.ItemSpec) : relativePath;
string? culture = MonoAndroidHelper.GetAssemblyCulture (assembly);
string fileName = Path.GetFileName (assembly.ItemSpec);
string assemblyName;

if (String.IsNullOrEmpty (culture)) {
assemblyName = fileName;
} else {
assemblyName = $"{culture}/{fileName}";
}

if (!uniqueAssemblyNames.Contains (assemblyName)) {
uniqueAssemblyNames.Add (assemblyName);
}
Expand Down
32 changes: 32 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,37 @@ public static string GetNativeLibsRootDirectoryPath (string androidBinUtilsDirec
string relPath = GetToolsRootDirectoryRelativePath (androidBinUtilsDirectory);
return Path.GetFullPath (Path.Combine (androidBinUtilsDirectory, relPath, "lib"));
}

public static string? GetAssemblyCulture (ITaskItem assembly)
{
// The best option
string? culture = assembly.GetMetadata ("Culture");
if (!String.IsNullOrEmpty (culture)) {
return TrimSlashes (culture);
}

// ...slightly worse
culture = assembly.GetMetadata ("RelativePath");
if (!String.IsNullOrEmpty (culture)) {
return TrimSlashes (Path.GetDirectoryName (culture));
}

// ...not ideal
culture = assembly.GetMetadata ("DestinationSubDirectory");
if (!String.IsNullOrEmpty (culture)) {
return TrimSlashes (culture);
}

return null;

string? TrimSlashes (string? s)
{
if (String.IsNullOrEmpty (s)) {
return null;
}

return s.TrimEnd ('/').TrimEnd ('\\');
}
}
}
}