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