|
1 |
| -using System; |
| 1 | +using System; |
2 | 2 | using System.IO;
|
3 | 3 | using NUnit.Framework;
|
4 | 4 | using Xamarin.ProjectTools;
|
@@ -644,5 +644,89 @@ protected override void OnCreate (Bundle bundle)
|
644 | 644 | }
|
645 | 645 | }
|
646 | 646 | }
|
| 647 | + |
| 648 | + [Test] |
| 649 | + public void CheckTheCorrectRuntimeAssemblyIsUsedFromNuget () |
| 650 | + { |
| 651 | + string monoandroidFramework; |
| 652 | + using (var builder = new Builder ()) { |
| 653 | + monoandroidFramework = builder.LatestMultiTargetFrameworkVersion (); |
| 654 | + } |
| 655 | + string path = Path.Combine (Root, "temp", TestName); |
| 656 | + var ns = new DotNetStandard () { |
| 657 | + ProjectName = "Dummy", |
| 658 | + Sdk = "MSBuild.Sdk.Extras/2.0.54", |
| 659 | + Sources = { |
| 660 | + new BuildItem.Source ("Class1.cs") { |
| 661 | + TextContent = () => @"public class Class1 { |
| 662 | +#if __ANDROID__ |
| 663 | + public static string Library => ""Android""; |
| 664 | +#else |
| 665 | + public static string Library => "".NET Standard""; |
| 666 | +#endif |
| 667 | +}", |
| 668 | + }, |
| 669 | + }, |
| 670 | + OtherBuildItems = { |
| 671 | + new BuildItem.NoActionResource ("$(OutputPath)netstandard2.0\\$(AssemblyName).dll") { |
| 672 | + TextContent = null, |
| 673 | + BinaryContent = null, |
| 674 | + Metadata = { |
| 675 | + { "PackagePath", "ref\\netstandard2.0" }, |
| 676 | + { "Pack", "True" } |
| 677 | + }, |
| 678 | + }, |
| 679 | + new BuildItem.NoActionResource ($"$(OutputPath){monoandroidFramework}\\$(AssemblyName).dll") { |
| 680 | + TextContent = null, |
| 681 | + BinaryContent = null, |
| 682 | + Metadata = { |
| 683 | + { "PackagePath", $"lib\\{monoandroidFramework}" }, |
| 684 | + { "Pack", "True" } |
| 685 | + }, |
| 686 | + }, |
| 687 | + }, |
| 688 | + }; |
| 689 | + ns.SetProperty ("TargetFrameworks", $"netstandard2.0;{monoandroidFramework}"); |
| 690 | + ns.SetProperty ("PackageId", "dummy.package.foo"); |
| 691 | + ns.SetProperty ("PackageVersion", "1.0.0"); |
| 692 | + ns.SetProperty ("GeneratePackageOnBuild", "True"); |
| 693 | + ns.SetProperty ("IncludeBuildOutput", "False"); |
| 694 | + ns.SetProperty ("Summary", "Test"); |
| 695 | + ns.SetProperty ("Description", "Test"); |
| 696 | + ns.SetProperty ("PackageOutputPath", path); |
| 697 | + |
| 698 | + |
| 699 | + var xa = new XamarinAndroidApplicationProject () { |
| 700 | + ProjectName = "App", |
| 701 | + PackageReferences = { |
| 702 | + new Package () { |
| 703 | + Id = "dummy.package.foo", |
| 704 | + Version = "1.0.0", |
| 705 | + }, |
| 706 | + }, |
| 707 | + OtherBuildItems = { |
| 708 | + new BuildItem.NoActionResource ("NuGet.config") { |
| 709 | + }, |
| 710 | + }, |
| 711 | + }; |
| 712 | + xa.SetProperty ("RestoreNoCache", "true"); |
| 713 | + xa.SetProperty ("RestorePackagesPath", "$(MSBuildThisFileDirectory)packages"); |
| 714 | + using (var nsb = CreateDllBuilder (Path.Combine (path, ns.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) |
| 715 | + using (var xab = CreateApkBuilder (Path.Combine (path, xa.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) { |
| 716 | + nsb.ThrowOnBuildFailure = xab.ThrowOnBuildFailure = false; |
| 717 | + Assert.IsTrue (nsb.Build (ns), "Build of NetStandard Library should have succeeded."); |
| 718 | + Assert.IsFalse (xab.Build (xa, doNotCleanupOnUpdate: true), "Build of App Library should have failed."); |
| 719 | + File.WriteAllText (Path.Combine (Root, xab.ProjectDirectory, "NuGet.config"), @"<?xml version='1.0' encoding='utf-8'?> |
| 720 | +<configuration> |
| 721 | + <packageSources> |
| 722 | + <add key='nuget.org' value='https://api.nuget.org/v3/index.json' protocolVersion='3' /> |
| 723 | + <add key='bug-testing' value='..' /> |
| 724 | + </packageSources> |
| 725 | +</configuration>"); |
| 726 | + Assert.IsTrue (xab.Build (xa, doNotCleanupOnUpdate: true), "Build of App Library should have succeeded."); |
| 727 | + string expected = Path.Combine ("dummy.package.foo", "1.0.0", "lib", monoandroidFramework, "Dummy.dll"); |
| 728 | + Assert.IsTrue (xab.LastBuildOutput.ContainsText (expected), $"Build should be using {expected}"); |
| 729 | + } |
| 730 | + } |
647 | 731 | }
|
648 | 732 | }
|
0 commit comments