From 59b20387794fefd4eeb0625df62531fa14a2ee75 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 26 Mar 2018 12:01:00 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Fix an issue where the 'ref' nuget is not found on windows. The previous commit 029a8b49 fixed up some issues with resolving the correct nuget. However on windows we get some weird pathing issues because the project.assets.json file is using `/` as path seperators. This is probably to be platform independent. But our string comparision was using what ever path we had, on windows that was `\`. So we never found the Library were we looking for. We also need to normalize the resulting full path to match the system path separator. --- .../Tasks/ResolveAssemblies.cs | 14 ++++++-------- .../Xamarin.Android.Common.targets | 1 - 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs index 1856b6e0d61..4b3799dfc9b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs @@ -31,8 +31,6 @@ public class ResolveAssemblies : AsyncTask public string TargetMoniker { get; set; } - public string NuGetPackageRoot { get; set; } - public string I18nAssemblies { get; set; } public string LinkMode { get; set; } @@ -76,7 +74,6 @@ bool Execute (DirectoryAssemblyResolver resolver) LogDebugMessage (" LinkMode: {0}", LinkMode); LogDebugTaskItems (" Assemblies:", Assemblies); LogDebugMessage (" ProjectAssetFile: {0}", ProjectAssetFile); - LogDebugMessage (" NuGetPackageRoot: {0}", NuGetPackageRoot); LogDebugMessage (" TargetMoniker: {0}", TargetMoniker); foreach (var dir in ReferenceAssembliesDirectory.Split (new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) @@ -107,10 +104,11 @@ bool Execute (DirectoryAssemblyResolver resolver) throw new InvalidOperationException ("Failed to load assembly " + assembly.ItemSpec); if (MonoAndroidHelper.IsReferenceAssembly (assemblyDef)) { // Resolve "runtime" library + var asmFullPath = Path.GetFullPath (assembly.ItemSpec); if (lockFile != null) - assemblyDef = ResolveRuntimeAssemblyForReferenceAssembly (lockFile, resolver, assembly_path); + assemblyDef = ResolveRuntimeAssemblyForReferenceAssembly (lockFile, resolver, asmFullPath); if (lockFile == null || assemblyDef == null) { - LogWarning ($"Ignoring {assembly_path} as it is a Reference Assembly"); + LogWarning ($"Ignoring {asmFullPath} as it is a Reference Assembly"); continue; } } @@ -156,7 +154,7 @@ bool Execute (DirectoryAssemblyResolver resolver) AssemblyDefinition ResolveRuntimeAssemblyForReferenceAssembly (LockFile lockFile, DirectoryAssemblyResolver resolver, string assemblyPath) { - if (string.IsNullOrEmpty(TargetMoniker) || string.IsNullOrEmpty (NuGetPackageRoot) || !Directory.Exists (NuGetPackageRoot)) + if (string.IsNullOrEmpty(TargetMoniker)) return null; var framework = NuGetFramework.Parse (TargetMoniker); @@ -171,7 +169,7 @@ 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, StringComparison.OrdinalIgnoreCase)); + var libraryPath = lockFile.Libraries.FirstOrDefault (x => path.StartsWith (x.Path.Replace('/', Path.DirectorySeparatorChar), StringComparison.OrdinalIgnoreCase)); if (libraryPath == null) continue; var library = target.Libraries.FirstOrDefault (x => String.Compare (x.Name, libraryPath.Name, StringComparison.OrdinalIgnoreCase) == 0); @@ -180,7 +178,7 @@ AssemblyDefinition ResolveRuntimeAssemblyForReferenceAssembly (LockFile lockFile var runtime = library.RuntimeAssemblies.FirstOrDefault (); if (runtime == null) continue; - path = Path.Combine (NuGetPackageRoot, libraryPath.Path, runtime.Path); + path = Path.Combine (folder.Path, libraryPath.Path, runtime.Path).Replace('/', Path.DirectorySeparatorChar); if (!File.Exists (path)) continue; LogDebugMessage ($"Attempting to load {path}"); diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 4f2c29db0dd..11d4c94836e 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -1608,7 +1608,6 @@ because xbuild doesn't support framework reference assemblies. I18nAssemblies="$(MandroidI18n)" LinkMode="$(AndroidLinkMode)" ProjectAssetFile="$(ProjectLockFile)" - NuGetPackageRoot="$(NuGetPackageRoot)" TargetMoniker="$(NuGetTargetMoniker)" ReferenceAssembliesDirectory="$(TargetFrameworkDirectory)">