@@ -223,5 +223,226 @@ public void CheckSignApk ([Values(true, false)] bool useApkSigner)
223223 Assert . IsTrue ( b . Build ( proj ) , "build failed" ) ;
224224 }
225225 }
226+
227+ [ Test ]
228+ public void NetStandardReferenceTest ( )
229+ {
230+ var netStandardProject = new DotNetStandard ( ) {
231+ Language = XamarinAndroidProjectLanguage . CSharp ,
232+ ProjectName = "XamFormsSample" ,
233+ ProjectGuid = Guid . NewGuid ( ) . ToString ( ) ,
234+ Sdk = "Microsoft.NET.Sdk" ,
235+ TargetFramework = "netstandard1.4" ,
236+ IsRelease = true ,
237+ PackageTargetFallback = "portable-net45+win8+wpa81+wp8" ,
238+ PackageReferences = {
239+ KnownPackages . XamarinFormsPCL_2_3_4_231 ,
240+ new Package ( ) {
241+ Id = "System.IO.Packaging" ,
242+ Version = "4.4.0" ,
243+ } ,
244+ // Uncomment when https://bugzilla.xamarin.com/show_bug.cgi?id=59313 gets fixed
245+ // new Package () {
246+ // Id = "Newtonsoft.Json",
247+ // Version = "10.0.3"
248+ // },
249+ } ,
250+ OtherBuildItems = {
251+ new BuildItem ( "None" ) {
252+ Remove = ( ) => "**\\ *.xaml" ,
253+ } ,
254+ new BuildItem ( "Compile" ) {
255+ Update = ( ) => "**\\ *.xaml.cs" ,
256+ DependentUpon = ( ) => "%(Filename)"
257+ } ,
258+ new BuildItem ( "EmbeddedResource" ) {
259+ Include = ( ) => "**\\ *.xaml" ,
260+ SubType = ( ) => "Designer" ,
261+ Generator = ( ) => "MSBuild:UpdateDesignTimeXaml" ,
262+ } ,
263+ } ,
264+ Sources = {
265+ new BuildItem . Source ( "App.xaml.cs" ) {
266+ TextContent = ( ) => @"using System;
267+ using System.Collections.Generic;
268+ using System.Linq;
269+ using System.Text;
270+ //using Newtonsoft.Json;
271+
272+ using Xamarin.Forms;
273+
274+ namespace XamFormsSample
275+ {
276+ public partial class App : Application
277+ {
278+ public App()
279+ {
280+ // Uncomment when https://bugzilla.xamarin.com/show_bug.cgi?id=59313 gets fixed
281+ // JsonConvert.DeserializeObject<string>(""test"");
282+ InitializeComponent();
283+ }
284+
285+ protected override void OnStart()
286+ {
287+ // Handle when your app starts
288+ }
289+
290+ protected override void OnSleep()
291+ {
292+ // Handle when your app sleeps
293+ }
294+
295+ protected override void OnResume()
296+ {
297+ // Handle when your app resumes
298+ }
299+ }
300+ }" ,
301+ } ,
302+ new BuildItem . Source ( "App.xaml" ) {
303+ TextContent = ( ) => @"<?xml version=""1.0"" encoding=""utf-8"" ?>
304+ <Application xmlns=""http://xamarin.com/schemas/2014/forms""
305+ xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
306+ x:Class=""XamFormsSample.App"">
307+ <Application.Resources>
308+ <!-- Application resource dictionary -->
309+ </Application.Resources>
310+ </Application>" ,
311+ } ,
312+ } ,
313+ } ;
314+
315+ var app = new XamarinAndroidApplicationProject ( ) {
316+ ProjectName = "App1" ,
317+ IsRelease = true ,
318+ UseLatestPlatformSdk = true ,
319+ References = {
320+ new BuildItem . Reference ( "Mono.Android.Export" ) ,
321+ new BuildItem . ProjectReference ( $ "..\\ { netStandardProject . ProjectName } \\ { netStandardProject . ProjectName } .csproj",
322+ netStandardProject . ProjectName , netStandardProject . ProjectGuid ) ,
323+ } ,
324+ PackageReferences = {
325+ KnownPackages . SupportDesign_25_4_0_1 ,
326+ KnownPackages . SupportV7CardView_24_2_1 ,
327+ KnownPackages . AndroidSupportV4_25_4_0_1 ,
328+ KnownPackages . SupportCoreUtils_25_4_0_1 ,
329+ KnownPackages . SupportMediaCompat_25_4_0_1 ,
330+ KnownPackages . SupportFragment_25_4_0_1 ,
331+ KnownPackages . SupportCoreUI_25_4_0_1 ,
332+ KnownPackages . SupportCompat_25_4_0_1 ,
333+ KnownPackages . SupportV7AppCompat_25_4_0_1 ,
334+ KnownPackages . XamarinForms_2_3_4_231 ,
335+ }
336+ } ;
337+ app . SetProperty ( KnownProperties . AndroidSupportedAbis , "x86;armeabi-v7a" ) ;
338+ var expectedFiles = new string [ ] {
339+ "Java.Interop.dll" ,
340+ "Mono.Android.dll" ,
341+ "mscorlib.dll" ,
342+ "mscorlib.dll.mdb" ,
343+ "System.Collections.Concurrent.dll" ,
344+ "System.Collections.dll" ,
345+ "System.Core.dll" ,
346+ "System.Diagnostics.Debug.dll" ,
347+ "System.dll" ,
348+ "System.Linq.dll" ,
349+ "System.Reflection.dll" ,
350+ "System.Reflection.Extensions.dll" ,
351+ "System.Runtime.dll" ,
352+ "System.Runtime.Extensions.dll" ,
353+ "System.Runtime.InteropServices.dll" ,
354+ "System.Runtime.Serialization.dll" ,
355+ "System.Threading.dll" ,
356+ "System.IO.Packaging.dll" ,
357+ "System.IO.Compression.dll" ,
358+ "System.IO.Compression.pdb" ,
359+ "Mono.Android.Export.dll" ,
360+ "Mono.Android.Export.pdb" ,
361+ "App1.dll" ,
362+ "App1.pdb" ,
363+ "FormsViewGroup.dll" ,
364+ "FormsViewGroup.dll.mdb" ,
365+ "Xamarin.Android.Support.Compat.dll" ,
366+ "Xamarin.Android.Support.Core.UI.dll" ,
367+ "Xamarin.Android.Support.Core.Utils.dll" ,
368+ "Xamarin.Android.Support.Design.dll" ,
369+ "Xamarin.Android.Support.Fragment.dll" ,
370+ "Xamarin.Android.Support.Media.Compat.dll" ,
371+ "Xamarin.Android.Support.v4.dll" ,
372+ "Xamarin.Android.Support.v7.AppCompat.dll" ,
373+ "Xamarin.Android.Support.Animated.Vector.Drawable.dll" ,
374+ "Xamarin.Android.Support.Vector.Drawable.dll" ,
375+ "Xamarin.Android.Support.Transition.dll" ,
376+ "Xamarin.Android.Support.v7.MediaRouter.dll" ,
377+ "Xamarin.Android.Support.v7.RecyclerView.dll" ,
378+ "Xamarin.Android.Support.Annotations.dll" ,
379+ "Xamarin.Android.Support.v7.CardView.dll" ,
380+ "Xamarin.Forms.Core.dll" ,
381+ "Xamarin.Forms.Core.dll.mdb" ,
382+ "Xamarin.Forms.Platform.Android.dll" ,
383+ "Xamarin.Forms.Platform.Android.dll.mdb" ,
384+ "Xamarin.Forms.Platform.dll" ,
385+ "Xamarin.Forms.Xaml.dll" ,
386+ "Xamarin.Forms.Xaml.dll.mdb" ,
387+ "XamFormsSample.dll" ,
388+ "XamFormsSample.pdb" ,
389+ "Mono.Android.pdb" ,
390+ "System.Core.pdb" ,
391+ "System.pdb" ,
392+ "Mono.Security.dll" ,
393+ "Mono.Security.pdb" ,
394+ "System.Xml.dll" ,
395+ "System.Xml.pdb" ,
396+ "System.ComponentModel.Composition.dll" ,
397+ "System.ComponentModel.Composition.pdb" ,
398+ "System.Net.Http.dll" ,
399+ "System.Net.Http.pdb" ,
400+ "System.Runtime.Serialization.pdb" ,
401+ "System.ServiceModel.Internals.dll" ,
402+ "System.ServiceModel.Internals.pdb" ,
403+ "System.Threading.Tasks.dll" ,
404+ "System.ObjectModel.dll" ,
405+ "System.Globalization.dll" ,
406+ "System.ComponentModel.dll" ,
407+ "System.Xml.ReaderWriter.dll" ,
408+ "System.Linq.Expressions.dll" ,
409+ "System.IO.dll" ,
410+ "System.Dynamic.Runtime.dll" ,
411+ "System.Text.RegularExpressions.dll" ,
412+ "System.Diagnostics.Tools.dll" ,
413+ } ;
414+ var path = Path . Combine ( "temp" , TestContext . CurrentContext . Test . Name ) ;
415+ using ( var builder = CreateDllBuilder ( Path . Combine ( path , netStandardProject . ProjectName ) ) ) {
416+ builder . RequiresMSBuild = true ;
417+ builder . Target = "Restore" ;
418+ Assert . IsTrue ( builder . Build ( netStandardProject ) , "XamFormsSample Nuget packages should have been restored." ) ;
419+ builder . Target = "Build" ;
420+ Assert . IsTrue ( builder . Build ( netStandardProject ) , "XamFormsSample should have built." ) ;
421+ using ( var ab = CreateApkBuilder ( Path . Combine ( path , app . ProjectName ) ) ) {
422+ ab . RequiresMSBuild = true ;
423+ ab . Target = "Restore" ;
424+ Assert . IsTrue ( ab . Build ( app ) , "App should have built." ) ;
425+ ab . Target = "SignAndroidPackage" ;
426+ Assert . IsTrue ( ab . Build ( app ) , "App should have built." ) ;
427+ var apk = Path . Combine ( Root , ab . ProjectDirectory ,
428+ app . IntermediateOutputPath , "android" , "bin" , "UnnamedProject.UnnamedProject.apk" ) ;
429+ using ( var zip = ZipHelper . OpenZip ( apk ) ) {
430+ var existingFiles = zip . Where ( a => a . FullName . StartsWith ( "assemblies/" , StringComparison . InvariantCultureIgnoreCase ) ) ;
431+ var missingFiles = expectedFiles . Where ( x => ! zip . ContainsEntry ( "assmelbies/" + Path . GetFileName ( x ) ) ) ;
432+ Assert . IsTrue ( missingFiles . Any ( ) ,
433+ string . Format ( "The following Expected files are missing. {0}" ,
434+ string . Join ( Environment . NewLine , missingFiles ) ) ) ;
435+ var additionalFiles = existingFiles . Where ( x => ! expectedFiles . Contains ( Path . GetFileName ( x . FullName ) ) ) ;
436+ Assert . IsTrue ( ! additionalFiles . Any ( ) ,
437+ string . Format ( "Unexpected Files found! {0}" ,
438+ string . Join ( Environment . NewLine , additionalFiles . Select ( x => x . FullName ) ) ) ) ;
439+ }
440+ if ( ! HasDevices )
441+ Assert . Ignore ( "Skipping Installation. No devices available." ) ;
442+ ab . Target = "Install" ;
443+ Assert . IsTrue ( ab . Build ( app ) , "App should have installed." ) ;
444+ }
445+ }
446+ }
226447 }
227448}
0 commit comments