Skip to content

Commit

Permalink
Add Net Standard Support
Browse files Browse the repository at this point in the history
This commit adds Net Standard Support for msbuild tests.
It also adds support for `PackageReference` for standard
xamarin.android projects.

Note We have to inject the PackageReference bits into a
standard project using xml. This is because the Project
api we are using does NOT support PackageReference items.
At least the version we have on mono doesn't.
  • Loading branch information
dellis1972 committed Sep 22, 2017
1 parent 87411b5 commit 185fea4
Show file tree
Hide file tree
Showing 12 changed files with 566 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,226 @@ public void ExplicitPackageNamingPolicy ()
Assert.IsTrue (text.Contains ("package unnamedproject;"), "expected package not found in the source.");
}
}

[Test]
public void NetStandardReferenceTest ()
{
var netStandardProject = new DotNetStandard () {
Language = XamarinAndroidProjectLanguage.CSharp,
ProjectName = "XamFormsSample",
ProjectGuid = Guid.NewGuid ().ToString (),
Sdk = "Microsoft.NET.Sdk",
TargetFramework = "netstandard1.4",
IsRelease = true,
PackageTargetFallback = "portable-net45+win8+wpa81+wp8",
PackageReferences = {
KnownPackages.XamarinFormsPCL_2_3_4_231,
new Package () {
Id = "System.IO.Packaging",
Version = "4.4.0",
},
// Uncomment when https://bugzilla.xamarin.com/show_bug.cgi?id=59313 gets fixed
// new Package () {
// Id = "Newtonsoft.Json",
// Version = "10.0.3"
// },
},
OtherBuildItems = {
new BuildItem ("None") {
Remove = () => "**\\*.xaml",
},
new BuildItem ("Compile") {
Update = () => "**\\*.xaml.cs",
DependentUpon = () => "%(Filename)"
},
new BuildItem ("EmbeddedResource") {
Include = () => "**\\*.xaml",
SubType = () => "Designer",
Generator = () => "MSBuild:UpdateDesignTimeXaml",
},
},
Sources = {
new BuildItem.Source ("App.xaml.cs") {
TextContent = () => @"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Newtonsoft.Json;
using Xamarin.Forms;
namespace XamFormsSample
{
public partial class App : Application
{
public App()
{
// Uncomment when https://bugzilla.xamarin.com/show_bug.cgi?id=59313 gets fixed
// JsonConvert.DeserializeObject<string>(""test"");
InitializeComponent();
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}",
},
new BuildItem.Source ("App.xaml") {
TextContent = () => @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Application xmlns=""http://xamarin.com/schemas/2014/forms""
xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
x:Class=""XamFormsSample.App"">
<Application.Resources>
<!-- Application resource dictionary -->
</Application.Resources>
</Application>",
},
},
};

var app = new XamarinAndroidApplicationProject () {
ProjectName = "App1",
IsRelease = true,
UseLatestPlatformSdk = true,
References = {
new BuildItem.Reference ("Mono.Android.Export"),
new BuildItem.ProjectReference ($"..\\{netStandardProject.ProjectName}\\{netStandardProject.ProjectName}.csproj",
netStandardProject.ProjectName, netStandardProject.ProjectGuid),
},
PackageReferences = {
KnownPackages.SupportDesign_25_4_0_1,
KnownPackages.SupportV7CardView_24_2_1,
KnownPackages.AndroidSupportV4_25_4_0_1,
KnownPackages.SupportCoreUtils_25_4_0_1,
KnownPackages.SupportMediaCompat_25_4_0_1,
KnownPackages.SupportFragment_25_4_0_1,
KnownPackages.SupportCoreUI_25_4_0_1,
KnownPackages.SupportCompat_25_4_0_1,
KnownPackages.SupportV7AppCompat_25_4_0_1,
KnownPackages.XamarinForms_2_3_4_231,
}
};
app.SetProperty (KnownProperties.AndroidSupportedAbis, "x86;armeabi-v7a");
var expectedFiles = new string [] {
"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",
"Xamarin.Android.Support.Design.dll",
"Xamarin.Android.Support.Fragment.dll",
"Xamarin.Android.Support.Media.Compat.dll",
"Xamarin.Android.Support.v4.dll",
"Xamarin.Android.Support.v7.AppCompat.dll",
"Xamarin.Android.Support.Animated.Vector.Drawable.dll",
"Xamarin.Android.Support.Vector.Drawable.dll",
"Xamarin.Android.Support.Transition.dll",
"Xamarin.Android.Support.v7.MediaRouter.dll",
"Xamarin.Android.Support.v7.RecyclerView.dll",
"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",
};
var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
using (var builder = CreateDllBuilder (Path.Combine (path, netStandardProject.ProjectName))) {
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))) {
ab.RequiresMSBuild = true;
ab.Target = "Restore";
Assert.IsTrue (ab.Build (app), "App should have built.");
ab.Target = "SignAndroidPackage";
Assert.IsTrue (ab.Build (app), "App should have built.");
var apk = Path.Combine (Root, ab.ProjectDirectory,
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 (),
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)));
Assert.IsTrue (!additionalFiles.Any (),
string.Format ("Unexpected Files found! {0}",
string.Join (Environment.NewLine, additionalFiles.Select (x => x.FullName))));
}
if (!HasDevices)
Assert.Ignore ("Skipping Installation. No devices available.");
ab.Target = "Install";
Assert.IsTrue (ab.Build (app), "App should have installed.");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static class KnownPackages
new BuildItem.Reference ("Xamarin.Android.Support.v13") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v13.20.0.0.4\\lib\\MonoAndroid32\\Xamarin.Android.Support.v13.dll" }
}
};
};
public static Package AndroidSupportV13Beta = new Package () {
Id = "Xamarin.Android.Support.v13",
Version = "21.0.0.0-beta1",
Expand All @@ -93,20 +93,20 @@ public static class KnownPackages
new BuildItem.Reference ("Xamarin.Android.Wearable") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Wear.1.0.0-preview7\\lib\\MonoAndroid10\\Xamarin.Android.Wearable.dll" }
}
};
};
public static Package SupportV7RecyclerView = new Package {
Id = "Xamarin.Android.Support.v7.RecyclerView",
Version="21.0.0.0-beta1",
TargetFramework="MonoAndroid523",
Version = "21.0.0.0-beta1",
TargetFramework = "MonoAndroid523",
References = {
new BuildItem.Reference ("Xamarin.Android.Support.V7.RecyclerView") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.RecyclerView.21.0.0.0-beta1\\lib\\MonoAndroid\\Xamarin.Android.Support.v7.RecyclerView.dll" }
}
};
};
public static Package SupportV7CardView = new Package {
Id = "Xamarin.Android.Support.v7.Cardview",
Version="21.0.3.0",
TargetFramework="MonoAndroid523",
Version = "21.0.3.0",
TargetFramework = "MonoAndroid523",
References = {
new BuildItem.Reference ("Xamarin.Android.Support.v7.CardView") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.CardView.21.0.3.0\\lib\\MonoAndroid403\\Xamarin.Android.Support.v7.CardView.dll" }
Expand All @@ -121,6 +121,15 @@ public static class KnownPackages
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.CardView.24.2.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v7.CardView.dll" }
}
};
public static Package SupportV7CardView_25_4_0_1 = new Package {
Id = "Xamarin.Android.Support.v7.Cardview",
Version = "25.4.0.1",
TargetFramework = "MonoAndroid70",
References = {
new BuildItem.Reference ("Xamarin.Android.Support.v7.CardView") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.CardView.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v7.CardView.dll" }
}
};
public static Package SupportV7AppCompat_21_0_3_0 = new Package {
Id = "Xamarin.Android.Support.v7.AppCompat",
Version = "21.0.3.0",
Expand Down Expand Up @@ -220,6 +229,15 @@ public static class KnownPackages
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.Palette.22.1.1.1\\lib\\MonoAndroid403\\Xamarin.Android.Support.v7.Palette.dll" }
}
};
public static Package SupportDesign_25_4_0_1 = new Package {
Id = "Xamarin.Android.Support.Design",
Version = "25.4.0.1",
TargetFramework = "MonoAndroid70",
References = {
new BuildItem.Reference ("Xamarin.Android.Support.Design") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Design.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Design.dll" }
}
};
public static Package GooglePlayServices_22_0_0_2 = new Package {
Id = "Xamarin.GooglePlayServices",
Version = "22.0.0.2",
Expand Down Expand Up @@ -265,6 +283,41 @@ public static class KnownPackages
},
}
};
public static Package XamarinFormsPCL_2_3_4_231 = new Package {
Id = "Xamarin.Forms",
Version = "2.3.4.231",
TargetFramework = "portable-net45+win+wp80+MonoAndroid10+xamarinios10+MonoTouch10",
References = {
new BuildItem.Reference ("Xamarin.Forms.Core") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.2.3.4.231\\lib\\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\\Xamarin.Forms.Core.dll"
},
new BuildItem.Reference ("Xamarin.Forms.Xaml") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.2.3.4.231\\lib\\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\\Xamarin.Forms.Xaml.dll"
},
}
};
public static Package XamarinForms_2_3_4_231 = new Package {
Id = "Xamarin.Forms",
Version = "2.3.4.231",
TargetFramework = "MonoAndroid44",
References = {
new BuildItem.Reference ("Xamarin.Forms.Platform.Android") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.2.3.4.231\\lib\\MonoAndroid10\\Xamarin.Forms.Platform.Android.dll"
},
new BuildItem.Reference ("FormsViewGroup") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.2.3.4.231\\lib\\MonoAndroid10\\FormsViewGroup.dll"
},
new BuildItem.Reference ("Xamarin.Forms.Core") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.2.3.4.231\\lib\\MonoAndroid10\\Xamarin.Forms.Core.dll"
},
new BuildItem.Reference ("Xamarin.Forms.Xaml") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.2.3.4.231\\lib\\MonoAndroid10\\Xamarin.Forms.Xaml.dll"
},
new BuildItem.Reference ("Xamarin.Forms.Platform") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.2.3.4.231\\lib\\MonoAndroid10\\Xamarin.Forms.Platform.dll"
},
}
};
public static Package CocosSharp_PCL_Shared_1_5_0_0 = new Package {
Id = "CocosSharp.PCL.Shared",
Version = "1.5.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Xamarin.ProjectTools
{
public abstract class XamarinAndroidProject : XamarinProject
public abstract class XamarinAndroidProject : DotNetXamarinProject
{
protected XamarinAndroidProject (string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
: base (debugConfigurationName, releaseConfigurationName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class BuildActions
{
public const string None = "None";
public const string ProjectReference = "ProjectReference";
public const string PackageReference = "PackageReference";
public const string Reference = "Reference";
public const string Compile = "Compile";
public const string EmbeddedResource = "EmbeddedResource";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,31 @@ public BuildItem (string buildAction, string include)
{
}

public BuildItem (string buildAction, Func<string> include)
public BuildItem (string buildAction, Func<string> include = null)
{
BuildAction = buildAction;
Include = include;
Metadata = new Dictionary<string, string> ();
Timestamp = DateTimeOffset.UtcNow;
Encoding = Encoding.UTF8;
Attributes = FileAttributes.Normal;
Generator = null;
Remove = null;
SubType = null;
Update = null;
DependentUpon = null;
Version = null;
}

public DateTimeOffset? Timestamp { get; set; }
public string BuildAction { get; set; }
public Func<string> Include { get; set; }
public Func<string> Remove { get; set; }
public Func<string> Update { get; set; }
public Func<string> SubType { get; set; }
public Func<string> Generator { get; set; }
public Func<string> DependentUpon { get; set; }
public Func<string> Version { get; set; }
public IDictionary<string,string> Metadata { get; private set; }
public Func<string> TextContent { get; set; }
public Func<byte[]> BinaryContent { get; set; }
Expand Down
Loading

0 comments on commit 185fea4

Please sign in to comment.