Skip to content
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

Better NetStandard Support #1185

Merged
merged 5 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,20 @@ public void NetStandardReferenceTest ()
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using System.IO.Packaging;

using Xamarin.Forms;

namespace XamFormsSample
{
public partial class App : Application
{
Package package;

public App()
{
JsonConvert.DeserializeObject<string>(""test"");
package = Package.Open ("""");
InitializeComponent();
}

Expand Down Expand Up @@ -338,29 +342,13 @@ protected override void OnResume()
"Java.Interop.dll",
"Mono.Android.dll",
"mscorlib.dll",
"mscorlib.dll.mdb",
"System.Collections.Concurrent.dll",
"System.Collections.dll",
"System.Core.dll",
"System.Diagnostics.Debug.dll",
"System.dll",
"System.Linq.dll",
"System.Reflection.dll",
"System.Reflection.Extensions.dll",
"System.Runtime.dll",
"System.Runtime.Extensions.dll",
"System.Runtime.InteropServices.dll",
"System.Runtime.Serialization.dll",
"System.Threading.dll",
"System.IO.Packaging.dll",
"System.IO.Compression.dll",
"System.IO.Compression.pdb",
"Mono.Android.Export.dll",
"Mono.Android.Export.pdb",
"App1.dll",
"App1.pdb",
"FormsViewGroup.dll",
"FormsViewGroup.dll.mdb",
"Xamarin.Android.Support.Compat.dll",
"Xamarin.Android.Support.Core.UI.dll",
"Xamarin.Android.Support.Core.Utils.dll",
Expand All @@ -377,38 +365,14 @@ protected override void OnResume()
"Xamarin.Android.Support.Annotations.dll",
"Xamarin.Android.Support.v7.CardView.dll",
"Xamarin.Forms.Core.dll",
"Xamarin.Forms.Core.dll.mdb",
"Xamarin.Forms.Platform.Android.dll",
"Xamarin.Forms.Platform.Android.dll.mdb",
"Xamarin.Forms.Platform.dll",
"Xamarin.Forms.Xaml.dll",
"Xamarin.Forms.Xaml.dll.mdb",
"XamFormsSample.dll",
"XamFormsSample.pdb",
"Mono.Android.pdb",
"System.Core.pdb",
"System.pdb",
"Mono.Security.dll",
"Mono.Security.pdb",
"System.Xml.dll",
"System.Xml.pdb",
"System.ComponentModel.Composition.dll",
"System.ComponentModel.Composition.pdb",
"System.Net.Http.dll",
"System.Net.Http.pdb",
"System.Runtime.Serialization.pdb",
"System.ServiceModel.Internals.dll",
"System.ServiceModel.Internals.pdb",
"System.Threading.Tasks.dll",
"System.ObjectModel.dll",
"System.Globalization.dll",
"System.ComponentModel.dll",
"System.Xml.ReaderWriter.dll",
"System.Linq.Expressions.dll",
"System.IO.dll",
"System.Dynamic.Runtime.dll",
"System.Text.RegularExpressions.dll",
"System.Diagnostics.Tools.dll",
"Newtonsoft.Json.dll",
"Microsoft.CSharp.dll",
"System.Numerics.dll",
Expand All @@ -418,12 +382,12 @@ protected override void OnResume()
using (var builder = CreateDllBuilder (Path.Combine (path, netStandardProject.ProjectName), cleanupOnDispose: false)) {
if (!Directory.Exists (builder.MicrosoftNetSdkDirectory))
Assert.Ignore ("Microsoft.NET.Sdk not found.");
builder.RequiresMSBuild = true;
builder.Target = "Restore";
Assert.IsTrue (builder.Build (netStandardProject), "XamFormsSample Nuget packages should have been restored.");
builder.Target = "Build";
Assert.IsTrue (builder.Build (netStandardProject), "XamFormsSample should have built.");
using (var ab = CreateApkBuilder (Path.Combine (path, app.ProjectName), cleanupOnDispose: false)) {
builder.RequiresMSBuild = true;
builder.Target = "Restore";
Assert.IsTrue (builder.Build (netStandardProject), "XamFormsSample Nuget packages should have been restored.");
builder.Target = "Build";
Assert.IsTrue (builder.Build (netStandardProject), "XamFormsSample should have built.");
ab.RequiresMSBuild = true;
ab.Target = "Restore";
Assert.IsTrue (ab.Build (app), "App should have built.");
Expand All @@ -433,8 +397,8 @@ protected override void OnResume()
app.IntermediateOutputPath, "android", "bin", "UnnamedProject.UnnamedProject.apk");
using (var zip = ZipHelper.OpenZip (apk)) {
var existingFiles = zip.Where (a => a.FullName.StartsWith ("assemblies/", StringComparison.InvariantCultureIgnoreCase));
var missingFiles = expectedFiles.Where (x => !zip.ContainsEntry ("assmelbies/" + Path.GetFileName (x)));
Assert.IsTrue (missingFiles.Any (),
var missingFiles = expectedFiles.Where (x => !zip.ContainsEntry ("assemblies/" + Path.GetFileName (x)));
Assert.IsFalse (missingFiles.Any (),
string.Format ("The following Expected files are missing. {0}",
string.Join (Environment.NewLine, missingFiles)));
var additionalFiles = existingFiles.Where (x => !expectedFiles.Contains (Path.GetFileName (x.FullName)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<XamarinAndroidVersion>@PACKAGE_VERSION@-@PACKAGE_VERSION_BUILD@</XamarinAndroidVersion>
<_JavaInteropReferences>Java.Interop;System.Runtime</_JavaInteropReferences>
<DependsOnSystemRuntime Condition=" '$(DependsOnSystemRuntime)' == '' ">true</DependsOnSystemRuntime>
<ImplicitlyExpandNETStandardFacades>false</ImplicitlyExpandNETStandardFacades>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be overridable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a common (maybe "de facto" standard) MSBuild property to control whether to include those references or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the iOS/Mac tooling does not allow this to be overridable. I suspect this is by design so NetStandard Facades are never included in the output.

<CopyNuGetImplementations Condition=" '$(CopyNuGetImplementations)' == ''">true</CopyNuGetImplementations>
<YieldDuringToolExecution Condition="'$(YieldDuringToolExecution)' == ''">true</YieldDuringToolExecution>
<LatestSupportedJavaVersion Condition="'$(LatestSupportedJavaVersion)' == ''">1.8.0</LatestSupportedJavaVersion>
Expand Down
49 changes: 30 additions & 19 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.PCLSupport.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- PCL Support -->
<PropertyGroup>
<_IsXBuild Condition="'$(MSBuildRuntimeVersion)' == ''">true</_IsXBuild>
<CheckForSystemRuntimeDependency>true</CheckForSystemRuntimeDependency>
<ImplicitlyExpandDesignTimeFacades>true</ImplicitlyExpandDesignTimeFacades>
<ResolveReferencesDependsOn>
Expand All @@ -14,32 +15,42 @@
GetReferenceAssemblyPaths
</ImplicitlyExpandDesignTimeFacadesDependsOn>
</PropertyGroup>

<UsingTask
TaskName="GetDependsOnNETStandard"
Condition="'$(_IsXBuild)' != 'true' And Exists ('$(MSBuildExtensionsPath)\Microsoft\Microsoft.NET.Build.Extensions\tools\net46\Microsoft.NET.Build.Extensions.Tasks.dll')"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\Microsoft.NET.Build.Extensions\tools\net46\Microsoft.NET.Build.Extensions.Tasks.dll" />

<Target Name="ImplicitlyExpandDesignTimeFacades" Condition="'$(ImplicitlyExpandDesignTimeFacades)' == 'true'" DependsOnTargets="$(ImplicitlyExpandDesignTimeFacadesDependsOn)">


<ItemGroup>
<_XACandidateNETStandardReferences Include="@(Reference);@(_ResolvedProjectReferencePaths)" />
<_XAInboxNETStandardFolders Include="$(TargetFrameworkDirectory)" />
</ItemGroup>

<PropertyGroup>
<_HasReferenceToSystemRuntime Condition="'$(DependsOnSystemRuntime)' == 'true' or '%(_ResolvedProjectReferencePaths.TargetPlatformIdentifier)' == 'Portable'
or '%(ReferenceDependencyPaths.Filename)' == 'System.Runtime'">true</_HasReferenceToSystemRuntime>
<_XANETStandardInbox Condition="'$(XI_NETStandardInbox)' == '' and Exists('%(XI_InboxNETStandardFolders.Identity)\netstandard.dll')">true</_XANETStandardInbox>
</PropertyGroup>

<ItemGroup Condition="'$(_HasReferenceToSystemRuntime)' == 'true'">
<_DesignTimeFacadeAssemblies Include="%(DesignTimeFacadeDirectories.Identity)*.dll"/>
</ItemGroup>

<CreateItem Include="%(_DesignTimeFacadeAssemblies.FileName)"
AdditionalMetadata="OriginalIdentity=%(_DesignTimeFacadeAssemblies.Identity)">
<Output TaskParameter="Include" ItemName="_DesignTimeFacadeAssemblies_Names" />
</CreateItem>

<CreateItem Include="%(ReferencePath.FileName)"
AdditionalMetadata="OriginalIdentity=%(ReferencePath.Identity)">
<Output TaskParameter="Include" ItemName="_ReferencePath_Names" />
</CreateItem>
<!--
Facades are expanded if we have a reference that depends on System.Runtime .
XI projects have `$(TargetFrameworkIdentifier) != .NETFramework`, so Microsoft.NET.Build.Extensions (which provides support for ns 2.0 projects) doesn't get
imported. And netstandard.dll reference, even if required, doesn't get added.
So, we need to check if any references depend on `netstandard`. And if so, expand the facades, which include netstandard.dll .
If $(_HasReferenceToSystemRuntime) is true, then the facades are going to be expanded anyway, so don't run this.
-->
<GetDependsOnNETStandard
Condition="'$(_HasReferenceToSystemRuntime)' != 'true' and '$(_IsXBuild)' != 'true' and '$(DependsOnNETStandard)' == '' and '@(_XACandidateNETStandardReferences)' != ''"
References="@(_XACandidateNETStandardReferences)">
<Output TaskParameter="DependsOnNETStandard" PropertyName="_XADependsOnNETStandard" />
</GetDependsOnNETStandard>

<ItemGroup>
<_DesignTimeFacadeAssemblies_Names Remove="@(_ReferencePath_Names)"/>

<ReferencePath Include="@(_DesignTimeFacadeAssemblies_Names->'%(OriginalIdentity)')">
<ItemGroup Condition="'$(_HasReferenceToSystemRuntime)' == 'true' or ('$(_XANETStandardInbox)' == 'true' and '$(_XADependsOnNETStandard)' == 'true')">
<_DesignTimeFacadeAssemblies Include="%(DesignTimeFacadeDirectories.Identity)*.dll"/>
<ReferencePath Remove="@(_DesignTimeFacadeAssemblies)"/>
<ReferencePath Include="%(_DesignTimeFacadeAssemblies.Identity)">
<WinMDFile>false</WinMDFile>
<CopyLocal>false</CopyLocal>
<ResolvedFrom>ImplicitlyExpandDesignTimeFacades</ResolvedFrom>
Expand All @@ -49,4 +60,4 @@

<Message Importance="Low" Text="Including @(ReferencePath)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandDesignTimeFacades'" />
</Target>
</Project>
</Project>