Skip to content

Commit c5b3baf

Browse files
committed
[Xamarin.Android.Build.Tasks] Crash when using NetStandard and Xamarin.Forms
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.
1 parent b16ee55 commit c5b3baf

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ bool Execute (DirectoryAssemblyResolver resolver)
7676
var assemblyDef = resolver.Load (assembly.ItemSpec);
7777
if (assemblyDef == null)
7878
throw new InvalidOperationException ("Failed to load assembly " + assembly.ItemSpec);
79+
if (MonoAndroidHelper.IsReferenceAssembly (assemblyDef)) {
80+
Log.LogWarning ($"Ignoring {assembly_path} as it is a Reference Assembly");
81+
continue;
82+
}
7983
topAssemblyReferences.Add (assemblyDef);
8084
assemblies.Add (Path.GetFullPath (assemblyDef.MainModule.FullyQualifiedName));
8185
}

src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,15 @@ public static bool IsFrameworkAssembly (string assembly, bool checkSdkPath)
303303

304304
public static bool IsReferenceAssembly (string assembly)
305305
{
306-
var a = AssemblyDefinition.ReadAssembly (assembly, new ReaderParameters() { InMemory = true, ReadSymbols = false, });
307-
if (!a.HasCustomAttributes)
306+
var a = AssemblyDefinition.ReadAssembly (assembly, new ReaderParameters () { InMemory = true, ReadSymbols = false, });
307+
return IsReferenceAssembly (a);
308+
}
309+
310+
public static bool IsReferenceAssembly (AssemblyDefinition assembly)
311+
{
312+
if (!assembly.HasCustomAttributes)
308313
return false;
309-
return a.CustomAttributes.Any (t => t.AttributeType.FullName == "System.Runtime.CompilerServices.ReferenceAssemblyAttribute");
314+
return assembly.CustomAttributes.Any (t => t.AttributeType.FullName == "System.Runtime.CompilerServices.ReferenceAssemblyAttribute");
310315
}
311316

312317
public static bool ExistsInFrameworkPath (string assembly)

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,10 +1492,9 @@ because xbuild doesn't support framework reference assemblies.
14921492
<FilteredAssemblies Include="$(OutDir)$(TargetFileName)"
14931493
Condition="Exists ('$(OutDir)$(TargetFileName)')" />
14941494
<FilteredAssemblies Include="%(ReferenceCopyLocalPaths.Identity)"
1495-
Condition="'%(ReferenceCopyLocalPaths.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '%(ReferenceCopyLocalPaths.Extension)' == '.dll' And '%(ReferenceCopyLocalPaths.DestinationSubDirectory)' == '' "/>
1496-
<!-- Fallback to @(ReferencePath) if @(ReferenceCopyLocalPaths) is empty. This is for xbuild support -->
1495+
Condition="'%(ReferenceCopyLocalPaths.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '%(ReferenceCopyLocalPaths.Extension)' == '.dll' "/>
14971496
<FilteredAssemblies Include="%(ReferencePath.Identity)"
1498-
Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '@(ReferenceCopyLocalPaths)' == '' "/>
1497+
Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' "/>
14991498
</ItemGroup>
15001499
<!-- Find all the assemblies this app requires -->
15011500
<ResolveAssemblies

0 commit comments

Comments
 (0)