From ac0e74cd5643b2085e1e030ae14139129fc9a6bc Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 10:42:58 +0000 Subject: [PATCH 1/3] [Xamarin.Android.Build.Tasks] Rework how we resolve netstandard Nugets Commit f7c942dd added support for replacing Reference assemblies with runtime assemblies. However a member of the Nuget team correctly pointed out that the Nuget does not akways have the same name as the package its in... So lets rework this code to do something else. We have the full path to the reference assembly. We also have the Nuget Project Model. This contains a list of the Paths for the cache's being used. So we use that information to attempt to figure out which package this reference came from. We can the use the Nuget ProjectModel to look up the replacement runtime assembly. Again this should just skip over things if we can't find what we want and issue the normal warning. --- .../Tasks/ResolveAssemblies.cs | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs index cf9c352fa2a..8519bc00091 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs @@ -108,7 +108,7 @@ bool Execute (DirectoryAssemblyResolver resolver) if (MonoAndroidHelper.IsReferenceAssembly (assemblyDef)) { // Resolve "runtime" library if (lockFile != null) - assemblyDef = ResolveRuntimeAssemblyForReferenceAssembly (lockFile, resolver, assemblyDef.Name); + assemblyDef = ResolveRuntimeAssemblyForReferenceAssembly (lockFile, resolver, assembly_path); if (lockFile == null || assemblyDef == null) { LogWarning ($"Ignoring {assembly_path} as it is a Reference Assembly"); continue; @@ -154,7 +154,7 @@ bool Execute (DirectoryAssemblyResolver resolver) readonly List do_not_package_atts = new List (); int indent = 2; - AssemblyDefinition ResolveRuntimeAssemblyForReferenceAssembly (LockFile lockFile, DirectoryAssemblyResolver resolver, AssemblyNameDefinition assemblyNameDefinition) + AssemblyDefinition ResolveRuntimeAssemblyForReferenceAssembly (LockFile lockFile, DirectoryAssemblyResolver resolver, string assemblyPath) { if (string.IsNullOrEmpty(TargetMoniker) || string.IsNullOrEmpty (NuGetPackageRoot) || !Directory.Exists (NuGetPackageRoot)) return null; @@ -169,18 +169,24 @@ AssemblyDefinition ResolveRuntimeAssemblyForReferenceAssembly (LockFile lockFile LogWarning ($"Could not resolve target for '{TargetMoniker}'"); return null; } - var libraryPath = lockFile.Libraries.FirstOrDefault (x => x.Name == assemblyNameDefinition.Name); - if (libraryPath == null) - return null; - var library = target.Libraries.FirstOrDefault (x => x.Name == assemblyNameDefinition.Name); - if (library == null) - return null; - var runtime = library.RuntimeAssemblies.FirstOrDefault (); - if (runtime == null) - return null; - var path = Path.Combine (NuGetPackageRoot, libraryPath.Path, runtime.Path); - LogDebugMessage ($"Attempting to load {path}"); - return resolver.Load (path, forceLoad: true); + foreach (var folder in lockFile.PackageFolders) { + var path = assembly_path.Replace (folder.Path, string.Empty); + var libraryPath = lockFile.Libraries.FirstOrDefault (x => path.StartsWith (x.Path)); + if (libraryPath == null) + continue; + var library = target.Libraries.FirstOrDefault (x => x.Name == libraryPath.Name); + if (libraryPath == null) + continue; + var runtime = library.RuntimeAssemblies.FirstOrDefault (); + if (runtime == null) + continue; + path = Path.Combine (NuGetPackageRoot, libraryPath.Path, runtime.Path); + if (!File.Exists (path)) + continue; + LogDebugMessage ($"Attempting to load {path}"); + return resolver.Load (path, forceLoad: true); + } + return null; } void AddAssemblyReferences (DirectoryAssemblyResolver resolver, ICollection assemblies, AssemblyDefinition assembly, bool topLevel) From 722e4c34a3e93080fd30a98cda9e465b59aef634 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 10:59:12 +0000 Subject: [PATCH 2/3] Fixed Typo --- src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs index 8519bc00091..de259dcba2e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs @@ -170,7 +170,7 @@ AssemblyDefinition ResolveRuntimeAssemblyForReferenceAssembly (LockFile lockFile return null; } foreach (var folder in lockFile.PackageFolders) { - var path = assembly_path.Replace (folder.Path, string.Empty); + var path = assemblyPath.Replace (folder.Path, string.Empty); var libraryPath = lockFile.Libraries.FirstOrDefault (x => path.StartsWith (x.Path)); if (libraryPath == null) continue; From 017fbea40038eba4989b3fe5b8897817adb4d3c3 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 22 Mar 2018 14:39:54 +0000 Subject: [PATCH 3/3] Updated based on feedback --- src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs index de259dcba2e..1856b6e0d61 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs @@ -171,10 +171,10 @@ AssemblyDefinition ResolveRuntimeAssemblyForReferenceAssembly (LockFile lockFile } foreach (var folder in lockFile.PackageFolders) { var path = assemblyPath.Replace (folder.Path, string.Empty); - var libraryPath = lockFile.Libraries.FirstOrDefault (x => path.StartsWith (x.Path)); + var libraryPath = lockFile.Libraries.FirstOrDefault (x => path.StartsWith (x.Path, StringComparison.OrdinalIgnoreCase)); if (libraryPath == null) continue; - var library = target.Libraries.FirstOrDefault (x => x.Name == libraryPath.Name); + var library = target.Libraries.FirstOrDefault (x => String.Compare (x.Name, libraryPath.Name, StringComparison.OrdinalIgnoreCase) == 0); if (libraryPath == null) continue; var runtime = library.RuntimeAssemblies.FirstOrDefault ();