From ed4bb9c35c94f6df0b94c7d30aba6b13157d8a62 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 15 Sep 2017 15:58:27 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Crash when using NetStandard and Xamarin.Forms (#850) Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=57342 Commit 8f2ae248 attempted to fix this issue. However it made the assumption that `@(ReferenceCopyLocalPaths)` contained the same items as `@(ReferencePath)`. However it did not. So we should use a combination of the two to figure out what assmeblies are needed. We need to disgard reference assemblies though, we do this by checking for the appropriate attributes before we add the assembly to the list of items we want to package. --- .../Tasks/ResolveAssemblies.cs | 4 ++++ .../Utilities/MonoAndroidHelper.cs | 11 ++++++++--- .../Xamarin.Android.Common.targets | 5 ++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs index cdb2ae84a7c..45ddd4d28bf 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs @@ -76,6 +76,10 @@ bool Execute (DirectoryAssemblyResolver resolver) var assemblyDef = resolver.Load (assembly.ItemSpec); if (assemblyDef == null) throw new InvalidOperationException ("Failed to load assembly " + assembly.ItemSpec); + if (MonoAndroidHelper.IsReferenceAssembly (assemblyDef)) { + Log.LogWarning ($"Ignoring {assembly_path} as it is a Reference Assembly"); + continue; + } topAssemblyReferences.Add (assemblyDef); assemblies.Add (Path.GetFullPath (assemblyDef.MainModule.FullyQualifiedName)); } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index 73776cd7f53..90c1545a37f 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -285,10 +285,15 @@ public static bool IsFrameworkAssembly (string assembly, bool checkSdkPath) public static bool IsReferenceAssembly (string assembly) { - var a = AssemblyDefinition.ReadAssembly (assembly, new ReaderParameters() { InMemory = true, ReadSymbols = false, }); - if (!a.HasCustomAttributes) + var a = AssemblyDefinition.ReadAssembly (assembly, new ReaderParameters () { InMemory = true, ReadSymbols = false, }); + return IsReferenceAssembly (a); + } + + public static bool IsReferenceAssembly (AssemblyDefinition assembly) + { + if (!assembly.HasCustomAttributes) return false; - return a.CustomAttributes.Any (t => t.AttributeType.FullName == "System.Runtime.CompilerServices.ReferenceAssemblyAttribute"); + return assembly.CustomAttributes.Any (t => t.AttributeType.FullName == "System.Runtime.CompilerServices.ReferenceAssemblyAttribute"); } public static bool ExistsInFrameworkPath (string assembly) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 12142ca59e2..33147608716 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -1486,10 +1486,9 @@ because xbuild doesn't support framework reference assemblies. - + Condition="'%(ReferenceCopyLocalPaths.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '%(ReferenceCopyLocalPaths.Extension)' == '.dll' And '%(ReferenceCopyLocalPaths.RelativeDir)' == '' "/> + Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' "/>