@@ -181,5 +181,214 @@ public void CheckIncludedNativeLibraries ()
181
181
}
182
182
}
183
183
}
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
+ "mscorlib.dll.mdb" ,
300
+ "System.Collections.Concurrent.dll" ,
301
+ "System.Collections.dll" ,
302
+ "System.Core.dll" ,
303
+ "System.Diagnostics.Debug.dll" ,
304
+ "System.dll" ,
305
+ "System.Linq.dll" ,
306
+ "System.Reflection.dll" ,
307
+ "System.Reflection.Extensions.dll" ,
308
+ "System.Runtime.dll" ,
309
+ "System.Runtime.Extensions.dll" ,
310
+ "System.Runtime.InteropServices.dll" ,
311
+ "System.Runtime.Serialization.dll" ,
312
+ "System.Threading.dll" ,
313
+ "System.IO.Packaging.dll" ,
314
+ "Mono.Android.Export.dll" ,
315
+ "Mono.Android.Export.pdb" ,
316
+ "App1.dll" ,
317
+ "App1.pdb" ,
318
+ "FormsViewGroup.dll" ,
319
+ "FormsViewGroup.dll.mdb" ,
320
+ "Xamarin.Android.Support.Compat.dll" ,
321
+ "Xamarin.Android.Support.Core.UI.dll" ,
322
+ "Xamarin.Android.Support.Core.Utils.dll" ,
323
+ "Xamarin.Android.Support.Design.dll" ,
324
+ "Xamarin.Android.Support.Fragment.dll" ,
325
+ "Xamarin.Android.Support.Media.Compat.dll" ,
326
+ "Xamarin.Android.Support.v4.dll" ,
327
+ "Xamarin.Android.Support.v7.AppCompat.dll" ,
328
+ "Xamarin.Android.Support.v7.CardView.dll" ,
329
+ "Xamarin.Forms.Core.dll" ,
330
+ "Xamarin.Forms.Core.dll.mdb" ,
331
+ "Xamarin.Forms.Platform.Android.dll" ,
332
+ "Xamarin.Forms.Platform.Android.dll.mdb" ,
333
+ "Xamarin.Forms.Platform.dll" ,
334
+ "Xamarin.Forms.Xaml.dll" ,
335
+ "Xamarin.Forms.Xaml.dll.mdb" ,
336
+ "XamFormsSample.dll" ,
337
+ "XamFormsSample.pdb" ,
338
+ "Mono.Android.pdb" ,
339
+ "System.Core.pdb" ,
340
+ "System.pdb" ,
341
+ "Mono.Security.dll" ,
342
+ "Mono.Security.pdb" ,
343
+ "System.Xml.dll" ,
344
+ "System.Xml.pdb" ,
345
+ "System.ComponentModel.Composition.dll" ,
346
+ "System.ComponentModel.Composition.pdb" ,
347
+ "System.Net.Http.dll" ,
348
+ "System.Net.Http.pdb" ,
349
+ "System.Runtime.Serialization.pdb" ,
350
+ "System.ServiceModel.Internals.dll" ,
351
+ "System.ServiceModel.Internals.pdb" ,
352
+ "System.Threading.Tasks.dll" ,
353
+ "System.ObjectModel.dll" ,
354
+ "System.Globalization.dll" ,
355
+ "System.ComponentModel.dll" ,
356
+ "System.Xml.ReaderWriter.dll" ,
357
+ "System.Linq.Expressions.dll" ,
358
+ "System.IO.dll" ,
359
+ "System.Dynamic.Runtime.dll" ,
360
+ "System.Text.RegularExpressions.dll" ,
361
+ "System.Diagnostics.Tools.dll" ,
362
+ } ;
363
+ var path = Path . Combine ( "temp" , TestContext . CurrentContext . Test . Name ) ;
364
+ using ( var builder = CreateDllBuilder ( Path . Combine ( path , netStandardProject . ProjectName ) ) ) {
365
+ builder . RequiresMSBuild = true ;
366
+ builder . Target = "Restore" ;
367
+ Assert . IsTrue ( builder . Build ( netStandardProject ) , "XamFormsSample Nuget packages should have been restored." ) ;
368
+ builder . Target = "Build" ;
369
+ Assert . IsTrue ( builder . Build ( netStandardProject ) , "XamFormsSample should have built." ) ;
370
+ using ( var ab = CreateApkBuilder ( Path . Combine ( path , app . ProjectName ) ) ) {
371
+ ab . RequiresMSBuild = true ;
372
+ Assert . IsTrue ( ab . Build ( app ) , "App should have built." ) ;
373
+ var apk = Path . Combine ( Root , ab . ProjectDirectory ,
374
+ app . IntermediateOutputPath , "android" , "bin" , "UnnamedProject.UnnamedProject.apk" ) ;
375
+ using ( var zip = ZipHelper . OpenZip ( apk ) ) {
376
+ var existingFiles = zip . Where ( a => a . FullName . StartsWith ( "assemblies/" , StringComparison . InvariantCultureIgnoreCase ) ) ;
377
+ var missingFiles = expectedFiles . Where ( x => ! zip . ContainsEntry ( "assmelbies/" + Path . GetFileName ( x ) ) ) ;
378
+ Assert . IsTrue ( missingFiles . Any ( ) ,
379
+ string . Format ( "The following Expected files are missing. {0}" ,
380
+ string . Join ( Environment . NewLine , missingFiles ) ) ) ;
381
+ var additionalFiles = existingFiles . Where ( x => ! expectedFiles . Contains ( Path . GetFileName ( x . FullName ) ) ) ;
382
+ Assert . IsTrue ( ! additionalFiles . Any ( ) ,
383
+ string . Format ( "Unexpected Files found! {0}" ,
384
+ string . Join ( Environment . NewLine , additionalFiles . Select ( x => x . FullName ) ) ) ) ;
385
+ }
386
+ if ( ! HasDevices )
387
+ Assert . Ignore ( "Skipping Installation. No devices available." ) ;
388
+ ab . Target = "Install" ;
389
+ Assert . IsTrue ( ab . Build ( app ) , "App should have installed." ) ;
390
+ }
391
+ }
392
+ }
184
393
}
185
394
}
0 commit comments