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