Skip to content

[Xamarin.Android.Build.Tasks] Rework how we resolve netstandard Nugets #1459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 22, 2018
Merged
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
34 changes: 20 additions & 14 deletions src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,7 +154,7 @@ bool Execute (DirectoryAssemblyResolver resolver)
readonly List<string> do_not_package_atts = new List<string> ();
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;
Expand All @@ -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 = assemblyPath.Replace (folder.Path, string.Empty);
var libraryPath = lockFile.Libraries.FirstOrDefault (x => path.StartsWith (x.Path, StringComparison.OrdinalIgnoreCase));
if (libraryPath == null)
continue;
var library = target.Libraries.FirstOrDefault (x => String.Compare (x.Name, libraryPath.Name, StringComparison.OrdinalIgnoreCase) == 0);
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<string> assemblies, AssemblyDefinition assembly, bool topLevel)
Expand Down