Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Crash when using NetStandard and Xamari…
Browse files Browse the repository at this point in the history
…n.Forms (#850)

Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=57342

Commit 8f2ae24 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.
  • Loading branch information
dellis1972 committed Oct 6, 2017
1 parent c7a00a5 commit ed4bb9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
11 changes: 8 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,10 +1486,9 @@ because xbuild doesn't support framework reference assemblies.
<FilteredAssemblies Include="$(OutDir)$(TargetFileName)"
Condition="Exists ('$(OutDir)$(TargetFileName)')" />
<FilteredAssemblies Include="%(ReferenceCopyLocalPaths.Identity)"
Condition="'%(ReferenceCopyLocalPaths.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '%(ReferenceCopyLocalPaths.Extension)' == '.dll' And '%(ReferenceCopyLocalPaths.DestinationSubDirectory)' == '' "/>
<!-- Fallback to @(ReferencePath) if @(ReferenceCopyLocalPaths) is empty. This is for xbuild support -->
Condition="'%(ReferenceCopyLocalPaths.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '%(ReferenceCopyLocalPaths.Extension)' == '.dll' And '%(ReferenceCopyLocalPaths.RelativeDir)' == '' "/>
<FilteredAssemblies Include="%(ReferencePath.Identity)"
Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '@(ReferenceCopyLocalPaths)' == '' "/>
Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' "/>
</ItemGroup>
<!-- Find all the assemblies this app requires -->
<ResolveAssemblies
Expand Down

0 comments on commit ed4bb9c

Please sign in to comment.