Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Don't package reference assemblies (dot…
Browse files Browse the repository at this point in the history
…net#706)

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

The investigation in the bug suggests that we are picking up a
reference assembly rather than a the actual implementation.
This is to do with the way netstandard nuget packages work, they
include both `ref` and `lib` folders.

In this case `ref` was being included in the package rather than
`lib`. This commit alters the `_ResolveAssemblies` to use

	@(ReferenceCopyLocalPaths)

This ItemGroup is populated with the correct items.
  • Loading branch information
dellis1972 authored and jonpryor committed Aug 4, 2017
1 parent ac05b8b commit 8f2ae24
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ TEST_APK_PROJECTS = \
# Syntax: $(call BUILD_TEST_APK,path/to/project.csproj)
define BUILD_TEST_APK
# Must use xabuild to ensure correct assemblies are resolved
MSBUILD="$(MSBUILD)" tools/scripts/xabuild /t:SignAndroidPackage $(1)
MSBUILD="$(MSBUILD)" tools/scripts/xabuild $(MSBUILD_FLAGS) /t:SignAndroidPackage $(1)
endef # BUILD_TEST_APK

run-apk-tests:
Expand Down
7 changes: 7 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ private void AddAssemblies (ZipArchiveEx apk)

int count = 0;
foreach (ITaskItem assembly in ResolvedUserAssemblies) {

if (MonoAndroidHelper.IsReferenceAssembly (assembly.ItemSpec)) {
Log.LogWarning ($"{assembly.ItemSpec} is a reference assembly!");
}
// Add assembly
apk.Archive.AddFile (assembly.ItemSpec, GetTargetDirectory (assembly.ItemSpec) + "/" + Path.GetFileName (assembly.ItemSpec), compressionMethod: CompressionMethod.Store);

Expand Down Expand Up @@ -305,6 +309,9 @@ private void AddAssemblies (ZipArchiveEx apk)
count = 0;
// Add framework assemblies
foreach (ITaskItem assembly in ResolvedFrameworkAssemblies) {
if (MonoAndroidHelper.IsReferenceAssembly (assembly.ItemSpec)) {
Log.LogWarning ($"{assembly.ItemSpec} is a reference assembly!");
}
apk.Archive.AddFile (assembly.ItemSpec, "assemblies/" + Path.GetFileName (assembly.ItemSpec), compressionMethod: CompressionMethod.Store);
var config = Path.ChangeExtension (assembly.ItemSpec, "dll.config");
AddAssemblyConfigEntry (apk, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Mono.Security.Cryptography;
using Xamarin.Android.Build.Utilities;
using Xamarin.Tools.Zip;
using Mono.Cecil;

#if MSBUILD
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -286,6 +287,14 @@ public static bool IsFrameworkAssembly (string assembly, bool checkSdkPath)
return TargetFrameworkDirectories == null || !checkSdkPath ? false : ExistsInFrameworkPath (assembly);
}

public static bool IsReferenceAssembly (string assembly)
{
var a = AssemblyDefinition.ReadAssembly (assembly, new ReaderParameters() { InMemory = true, ReadSymbols = false, });
if (!a.HasCustomAttributes)
return false;
return a.CustomAttributes.Any (t => t.AttributeType.FullName == "System.Runtime.CompilerServices.ReferenceAssemblyAttribute");
}

public static bool ExistsInFrameworkPath (string assembly)
{
return TargetFrameworkDirectories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,11 @@ because xbuild doesn't support framework reference assemblies.
<Target Name="_ResolveAssemblies">
<!--- Remove the ImplicitlyExpandDesignTimeFacades assemblies. We have already build the app there are not required for packaging -->
<ItemGroup>
<FilteredAssemblies Include="@(ReferencePath)" Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades'" />
<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 -->
<FilteredAssemblies Include="%(ReferencePath.Identity)"
Condition="'%(ReferencePath.ResolvedFrom)' != 'ImplicitlyExpandDesignTimeFacades' And '@(ReferenceCopyLocalPaths)' == '' "/>
</ItemGroup>
<!-- Find all the assemblies this app requires -->
<ResolveAssemblies
Expand Down

0 comments on commit 8f2ae24

Please sign in to comment.