diff --git a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.AppExtension.CSharp.targets b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.AppExtension.CSharp.targets index 6556ac487667..66c45839b6e0 100644 --- a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.AppExtension.CSharp.targets +++ b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.AppExtension.CSharp.targets @@ -22,6 +22,10 @@ Copyright (C) 2014 Xamarin. All rights reserved. v4.5 __UNIFIED__;__MACOS__;$(DefineConstants) + + + + true diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.CSharp.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.CSharp.targets index 0a1ec24e5626..d58a2dc4813d 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.CSharp.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.CSharp.targets @@ -22,6 +22,10 @@ Copyright (C) 2014-2016 Xamarin. All rights reserved. Xamarin.TVOS v1.0 + + + true + <_IsUnifiedDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__UNIFIED__($|;)')) <_IsMobileDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__MOBILE__($|;)')) <_IsTVOSDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__TVOS__($|;)')) diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.Common.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.Common.targets index ea26a762ef35..10f110b9c8d9 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.Common.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.Common.targets @@ -18,6 +18,9 @@ Copyright (C) 2014-2016 Xamarin. All rights reserved. True .appex + + + true diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.FSharp.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.FSharp.targets index 4a2e44693b7e..d3cf738ff8a1 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.FSharp.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.TVOS.AppExtension.FSharp.targets @@ -21,6 +21,11 @@ Copyright (C) 2014-2016 Xamarin. All rights reserved. Xamarin.TVOS v1.0 + + + + true + <_IsUnifiedDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__UNIFIED__($|;)')) <_IsMobileDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__MOBILE__($|;)')) <_IsTVOSDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__TVOS__($|;)')) diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.CSharp.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.CSharp.targets index 1bd34c322624..59031d7b5135 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.CSharp.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.CSharp.targets @@ -22,6 +22,10 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved. Xamarin.WatchOS v1.0 + + + true + <_IsUnifiedDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__UNIFIED__($|;)')) <_IsMobileDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__MOBILE__($|;)')) <_IsWATCHOSDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__WATCHOS__($|;)')) diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.Common.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.Common.targets index 29df96d78bd0..54d622b8998a 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.Common.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.Common.targets @@ -20,6 +20,10 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved. True .appex NSUrlSessionHandler + + + + true diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.FSharp.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.FSharp.targets index f607f10ac5a5..dbf2c3d60365 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.FSharp.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.WatchOS.AppExtension.FSharp.targets @@ -21,6 +21,11 @@ Copyright (C) 2015-2016 Xamarin. All rights reserved. Xamarin.WatchOS v1.0 + + + + true + <_IsUnifiedDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__UNIFIED__($|;)')) <_IsMobileDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__MOBILE__($|;)')) <_IsWATCHOSDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__WATCHOS__($|;)')) diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.CSharp.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.CSharp.targets index cdc915962768..a3950b7b0a28 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.CSharp.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.CSharp.targets @@ -22,6 +22,23 @@ Copyright (C) 2014-2016 Xamarin. All rights reserved. Xamarin.iOS v1.0 + + + true + <_IsUnifiedDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__UNIFIED__($|;)')) <_IsMobileDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__MOBILE__($|;)')) <_IsIOSDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__IOS__($|;)')) diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.FSharp.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.FSharp.targets index f184858fee8f..ec337c4e7956 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.FSharp.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.AppExtension.FSharp.targets @@ -22,6 +22,10 @@ Copyright (C) 2014-2016 Xamarin. All rights reserved. Xamarin.iOS v1.0 + + + true + <_IsUnifiedDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__UNIFIED__($|;)')) <_IsMobileDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__MOBILE__($|;)')) <_IsIOSDefined>$([System.Text.RegularExpressions.Regex]::IsMatch('$(DefineConstants.Trim())', '(^|;)__IOS__($|;)')) diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets index 6e262031e35c..86c9659766fe 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets @@ -786,6 +786,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. + diff --git a/msbuild/tests/MyAppWithPackageReference/AppDelegate.cs b/msbuild/tests/MyAppWithPackageReference/AppDelegate.cs new file mode 100644 index 000000000000..a3de038442e7 --- /dev/null +++ b/msbuild/tests/MyAppWithPackageReference/AppDelegate.cs @@ -0,0 +1,26 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +using Foundation; +using UIKit; + +namespace MyTabbedApplication +{ + [Register ("AppDelegate")] + public partial class AppDelegate : UIApplicationDelegate + { + public override UIWindow Window { + get; + set; + } + + // This is the main entry point of the application. + static void Main (string[] args) + { + Console.WriteLine (typeof (Newtonsoft.Json.JsonReader)); + UIApplication.Main (args, null, "AppDelegate"); + } + } +} + diff --git a/msbuild/tests/MyAppWithPackageReference/Info.plist b/msbuild/tests/MyAppWithPackageReference/Info.plist new file mode 100644 index 000000000000..af6b15db908a --- /dev/null +++ b/msbuild/tests/MyAppWithPackageReference/Info.plist @@ -0,0 +1,43 @@ + + + + + CFBundleDisplayName + MyAppWithPackageReference + CFBundleIdentifier + com.xamarin.MyAppWithPackageReference + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 9.3 + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CFBundleName + MyAppWithPackageReference + + diff --git a/msbuild/tests/MyAppWithPackageReference/MyAppWithPackageReference.csproj b/msbuild/tests/MyAppWithPackageReference/MyAppWithPackageReference.csproj new file mode 100644 index 000000000000..29fd106bb7b2 --- /dev/null +++ b/msbuild/tests/MyAppWithPackageReference/MyAppWithPackageReference.csproj @@ -0,0 +1,70 @@ + + + + Debug + iPhoneSimulator + {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {8FEBEE38-9A70-4434-8659-1C96138567DF} + Exe + MyAppWithPackageReference + Resources + MyAppWithPackageReference + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG; + x86_64 + None + true + + + full + true + bin\iPhoneSimulator\Release + x86_64 + None + + + true + full + false + bin\iPhone\Debug + DEBUG; + ARM64 + iPhone Developer + true + + + full + true + bin\iPhone\Release + ARM64 + iPhone Developer + + + + + + + + + + + + + + + + + + + + {D1F9F9CC-B3E5-49B2-8F71-7FF2B0B57E08} + MyExtensionWithPackageReference + True + + + \ No newline at end of file diff --git a/msbuild/tests/MyExtensionWithPackageReference/ActionViewController.cs b/msbuild/tests/MyExtensionWithPackageReference/ActionViewController.cs new file mode 100644 index 000000000000..8f7cae03d881 --- /dev/null +++ b/msbuild/tests/MyExtensionWithPackageReference/ActionViewController.cs @@ -0,0 +1,21 @@ +using System; +using System.Drawing; + +using Foundation; +using UIKit; + +namespace MyExtensionWithPackageReference +{ + public partial class ActionViewController : UIViewController + { + public ActionViewController (IntPtr handle) : base (handle) + { + Console.WriteLine (typeof (Newtonsoft.Json.JsonReader)); + } + + partial void DoneClicked (NSObject sender) + { + } + } +} + diff --git a/msbuild/tests/MyExtensionWithPackageReference/ActionViewController.designer.cs b/msbuild/tests/MyExtensionWithPackageReference/ActionViewController.designer.cs new file mode 100644 index 000000000000..e7baf5d6670a --- /dev/null +++ b/msbuild/tests/MyExtensionWithPackageReference/ActionViewController.designer.cs @@ -0,0 +1,23 @@ +// +// This file has been generated automatically by MonoDevelop to store outlets and +// actions made in the Xcode designer. If it is removed, they will be lost. +// Manual changes to this file may not be handled correctly. +// +using Foundation; + +namespace MyExtensionWithPackageReference +{ + [Register ("ActionViewController")] + partial class ActionViewController + { + [Outlet] + UIKit.UIImageView imageView { get; set; } + + [Action ("DoneClicked:")] + partial void DoneClicked (Foundation.NSObject sender); + + void ReleaseDesignerOutlets () + { + } + } +} diff --git a/msbuild/tests/MyExtensionWithPackageReference/Entitlements.plist b/msbuild/tests/MyExtensionWithPackageReference/Entitlements.plist new file mode 100644 index 000000000000..9ae599370b42 --- /dev/null +++ b/msbuild/tests/MyExtensionWithPackageReference/Entitlements.plist @@ -0,0 +1,6 @@ + + + + + + diff --git a/msbuild/tests/MyExtensionWithPackageReference/Info.plist b/msbuild/tests/MyExtensionWithPackageReference/Info.plist new file mode 100644 index 000000000000..d6be9e3c8f82 --- /dev/null +++ b/msbuild/tests/MyExtensionWithPackageReference/Info.plist @@ -0,0 +1,53 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + MyExtensionWithPackageReference + CFBundleIdentifier + com.xamarin.MyAppWithPackageReference.MyExtensionWithPackageReference + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + MyExtensionWithPackageReference + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + NSExtension + + NSExtensionAttributes + + NSExtensionActivationRule + + NSExtensionActivationSupportsFileWithMaxCount + 0 + NSExtensionActivationSupportsImageWithMaxCount + 1 + NSExtensionActivationSupportsMovieWithMaxCount + 0 + NSExtensionActivationSupportsText + + NSExtensionActivationSupportsWebURLWithMaxCount + 0 + + NSExtensionPointName + com.apple.ui-services + NSExtensionPointVersion + 1.0 + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.ui-services + + MinimumOSVersion + 9.3 + + diff --git a/msbuild/tests/MyExtensionWithPackageReference/MainInterface.storyboard b/msbuild/tests/MyExtensionWithPackageReference/MainInterface.storyboard new file mode 100644 index 000000000000..1efe512bd6f2 --- /dev/null +++ b/msbuild/tests/MyExtensionWithPackageReference/MainInterface.storyboard @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msbuild/tests/MyExtensionWithPackageReference/MyExtensionWithPackageReference.csproj b/msbuild/tests/MyExtensionWithPackageReference/MyExtensionWithPackageReference.csproj new file mode 100644 index 000000000000..92c3019c59b6 --- /dev/null +++ b/msbuild/tests/MyExtensionWithPackageReference/MyExtensionWithPackageReference.csproj @@ -0,0 +1,73 @@ + + + + Debug + iPhoneSimulator + {EE2C853D-36AF-4FDB-B1AD-8E90477E2198};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {D1F9F9CC-B3E5-49B2-8F71-7FF2B0B57E08} + Library + MyExtensionWithPackageReference + Resources + MyExtensionWithPackageReference + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG; + x86_64 + None + true + + + full + true + bin\iPhoneSimulator\Release + x86_64 + None + + + true + full + false + bin\iPhone\Debug + DEBUG; + prompt + ARM64 + Entitlements.plist + iPhone Developer + true + + + full + true + bin\iPhone\Release + Entitlements.plist + ARM64 + iPhone Developer + + + + + + + + + + + + + + + + + + + + + ActionViewController.cs + + + + \ No newline at end of file diff --git a/msbuild/tests/Xamarin.iOS.Tasks.Tests/ProjectsTests/ProjectReference.cs b/msbuild/tests/Xamarin.iOS.Tasks.Tests/ProjectsTests/ProjectReference.cs new file mode 100644 index 000000000000..fa3df08be42a --- /dev/null +++ b/msbuild/tests/Xamarin.iOS.Tasks.Tests/ProjectsTests/ProjectReference.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; +using NUnit.Framework; + +using Xamarin.Tests; + +namespace Xamarin.iOS.Tasks +{ + [TestFixture ("iPhone")] + [TestFixture ("iPhoneSimulator")] + [Ignore ("https://github.com/xamarin/xamarin-macios/issues/4110")] + public class ProjectReferenceTests : ProjectTest + { + + public ProjectReferenceTests (string platform) : base (platform) + { + } + + [Test] + public void BasicTest () + { + // We set MSBuildExtensionsPath when building with xbuild to redirect to our locally build XI/XM, but that confuses MSBuild, which uses MSBuildExtensionsPathFallbackPathsOverride instead. + // So if MSBuildExtensionsPath is set, move the value temporarily to MSBuildExtensionsPathFallbackPathsOverride instead, since we're using MSBuild here. + // This will become unnecessary when PR #4111 is merged. + var msbuildExtensions = Environment.GetEnvironmentVariable ("MSBuildExtensionsPath"); + if (!string.IsNullOrEmpty (msbuildExtensions)) { + Environment.SetEnvironmentVariable ("MSBuildExtensionsPath", null); + Environment.SetEnvironmentVariable ("MSBuildExtensionsPathFallbackPathsOverride", msbuildExtensions); + } + try { + NugetRestore ("../MyAppWithPackageReference/MyAppWithPackageReference.csproj"); + NugetRestore ("../MyExtensionWithPackageReference/MyExtensionWithPackageReference.csproj"); + + // Can't use the in-process MSBuild engine, because it complains that the project file is invalid (the attribute 'Version' in the element '' is unrecognized) + var rv = ExecutionHelper.Execute ("msbuild", $"../MyAppWithPackageReference/MyAppWithPackageReference.csproj /p:Platform={Platform} /p:Configuration=Debug", out var output); + if (rv != 0) { + Console.WriteLine ("Build failed:"); + Console.WriteLine (output); + Assert.Fail ("Build failed"); + } + } finally { + if (!string.IsNullOrEmpty (msbuildExtensions)) { + Environment.SetEnvironmentVariable ("MSBuildExtensionsPath", msbuildExtensions); + Environment.SetEnvironmentVariable ("MSBuildExtensionsPathFallbackPathsOverride", null); + } + } + } + } +} + diff --git a/msbuild/tests/Xamarin.iOS.Tasks.Tests/TestHelpers/TestBase.cs b/msbuild/tests/Xamarin.iOS.Tasks.Tests/TestHelpers/TestBase.cs index 9a4feedf19ce..dc4417e4727c 100644 --- a/msbuild/tests/Xamarin.iOS.Tasks.Tests/TestHelpers/TestBase.cs +++ b/msbuild/tests/Xamarin.iOS.Tasks.Tests/TestHelpers/TestBase.cs @@ -3,11 +3,15 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text; using Microsoft.Build.BuildEngine; using Microsoft.Build.Utilities; using NUnit.Framework; using Xamarin.MacDev; +using Xamarin.Tests; +using Xamarin.Utils; + namespace Xamarin.iOS.Tasks { public abstract class TestBase @@ -344,6 +348,16 @@ protected void AssertValidDeviceBuild (string platform) if (!Xamarin.Tests.Configuration.include_device && platform == "iPhone") Assert.Ignore ("This build does not include device support."); } + + public static void NugetRestore (string project) + { + var rv = ExecutionHelper.Execute ("nuget", $"restore {StringUtils.Quote (project)}", out var output); + if (rv != 0) { + Console.WriteLine ("nuget restore failed:"); + Console.WriteLine (output); + Assert.Fail ($"'nuget restore' failed for {project}"); + } + } } public class ProjectPaths : Dictionary { diff --git a/msbuild/tests/Xamarin.iOS.Tasks.Tests/Xamarin.iOS.Tasks.Tests.csproj b/msbuild/tests/Xamarin.iOS.Tasks.Tests/Xamarin.iOS.Tasks.Tests.csproj index 1f2f817bd88b..c6e8dd7dac62 100644 --- a/msbuild/tests/Xamarin.iOS.Tasks.Tests/Xamarin.iOS.Tasks.Tests.csproj +++ b/msbuild/tests/Xamarin.iOS.Tasks.Tests/Xamarin.iOS.Tasks.Tests.csproj @@ -107,6 +107,8 @@ ExecutionHelper.cs + + diff --git a/tests/common/mac/Finder/FinderExtensionTest.csproj b/tests/common/mac/Finder/FinderExtensionTest.csproj index 8e5fcb31ae03..9d5ca82afea6 100644 --- a/tests/common/mac/Finder/FinderExtensionTest.csproj +++ b/tests/common/mac/Finder/FinderExtensionTest.csproj @@ -4,7 +4,7 @@ Debug AnyCPU {B20EB7A2-A5ED-4CB9-95B3-58209092BF69} - {889C2465-30A1-4310-B175-96B1F4D843DE};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {10CE9E57-9141-4DF0-916A-2C4FD4EE2A73};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library FinderExtensionTest FinderExtensionTest @@ -61,4 +61,4 @@ - \ No newline at end of file + diff --git a/tests/common/mac/ProjectTestHelpers.cs b/tests/common/mac/ProjectTestHelpers.cs index 3999177c3335..92bf8d7e25c6 100644 --- a/tests/common/mac/ProjectTestHelpers.cs +++ b/tests/common/mac/ProjectTestHelpers.cs @@ -394,12 +394,7 @@ public static string RunGeneratedUnifiedExecutable (UnifiedTestConfig config) public static OutputText TestUnifiedExecutable (UnifiedTestConfig config, bool shouldFail = false, bool useMSBuild = false, string[] environment = null) { - // If we've already generated guid bits for this config, don't tack on a second copy - if (config.guid == Guid.Empty) - { - config.guid = Guid.NewGuid (); - config.TestCode += GenerateOutputCommand (config.TmpDir, config.guid); - } + AddGUIDTestCode (config); string buildOutput = GenerateAndBuildUnifiedExecutable (config, shouldFail, useMSBuild, environment); if (shouldFail) @@ -410,6 +405,15 @@ public static OutputText TestUnifiedExecutable (UnifiedTestConfig config, bool s return new OutputText (buildOutput, runOutput); } + public static void AddGUIDTestCode (UnifiedTestConfig config) + { + // If we've already generated guid bits for this config, don't tack on a second copy + if (config.guid == Guid.Empty) { + config.guid = Guid.NewGuid (); + config.TestCode += GenerateOutputCommand (config.TmpDir, config.guid); + } + } + public static OutputText TestClassicExecutable (string tmpDir, string testCode = "", string csprojConfig = "", bool shouldFail = false, bool includeMonoRuntime = false) { Guid guid = Guid.NewGuid (); @@ -483,7 +487,12 @@ public static string FindSourceDirectory () return Path.Combine(assemblyDirectory, TestDirectory + "common/mac"); } - static string CopyFileWithSubstitutions (string src, string target, Func replacementAction) + public static void CopyDirectory (string src, string target) + { + Xamarin.Bundler.Driver.RunCommand ("/bin/cp", $"-r {src} {target}"); + } + + public static string CopyFileWithSubstitutions (string src, string target, Func replacementAction) { string text = replacementAction (System.IO.File.ReadAllText (src)); System.IO.File.WriteAllText (target, text); @@ -545,6 +554,16 @@ static string GenerateOutputCommand (string tmpDir, Guid guid) { return string.Format ("System.IO.File.Create(\"{0}\").Dispose();", Path.Combine (tmpDir, guid.ToString ())); } + + public static void NugetRestore (string project) + { + var rv = ExecutionHelper.Execute ("nuget", $"restore {StringUtils.Quote (project)}", out var output); + if (rv != 0) { + Console.WriteLine ("nuget restore failed:"); + Console.WriteLine (output); + Assert.Fail ($"'nuget restore' failed for {project}"); + } + } } static class PlatformHelpers diff --git a/tests/common/mac/Share/ShareExtensionTest.csproj b/tests/common/mac/Share/ShareExtensionTest.csproj index 59ac3bfe91b1..63f3f5c74661 100644 --- a/tests/common/mac/Share/ShareExtensionTest.csproj +++ b/tests/common/mac/Share/ShareExtensionTest.csproj @@ -4,7 +4,7 @@ Debug AnyCPU {8D3616B0-B9BC-46E0-A67B-7D0AEA20420C} - {889C2465-30A1-4310-B175-96B1F4D843DE};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {10CE9E57-9141-4DF0-916A-2C4FD4EE2A73};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library ShareExtensionTest ShareExtensionTest @@ -67,4 +67,4 @@ - \ No newline at end of file + diff --git a/tests/common/mac/Today/TodayExtensionTest.csproj b/tests/common/mac/Today/TodayExtensionTest.csproj index e4f99bc96b11..7017b5b72ae8 100644 --- a/tests/common/mac/Today/TodayExtensionTest.csproj +++ b/tests/common/mac/Today/TodayExtensionTest.csproj @@ -4,7 +4,7 @@ Debug AnyCPU {005176FB-37A1-4308-8C2A-07B7ED3E0064} - {889C2465-30A1-4310-B175-96B1F4D843DE};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {10CE9E57-9141-4DF0-916A-2C4FD4EE2A73};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library TodayExtensionTest TodayExtensionTest @@ -71,4 +71,5 @@ - \ No newline at end of file +%ITEMGROUP% + diff --git a/tests/common/mac/Today/TodayViewController.cs b/tests/common/mac/Today/TodayViewController.cs index 78416c030c0d..c0fc2acbc843 100644 --- a/tests/common/mac/Today/TodayViewController.cs +++ b/tests/common/mac/Today/TodayViewController.cs @@ -17,7 +17,7 @@ public TodayViewController (IntPtr handle) : base (handle) public override void ViewDidLoad () { base.ViewDidLoad (); - +%TESTCODE% // Do any additional setup after loading the view. } diff --git a/tests/mmptest/mmptest.csproj b/tests/mmptest/mmptest.csproj index 31b9c59baea7..97181531b5da 100644 --- a/tests/mmptest/mmptest.csproj +++ b/tests/mmptest/mmptest.csproj @@ -108,6 +108,7 @@ + diff --git a/tests/mmptest/src/ExtensionTests.cs b/tests/mmptest/src/ExtensionTests.cs index 06d733b43db0..d3335cfd6fe9 100644 --- a/tests/mmptest/src/ExtensionTests.cs +++ b/tests/mmptest/src/ExtensionTests.cs @@ -20,8 +20,12 @@ public void TodayExtension_SmokeTest () MMPTests.RunMMPTest (tmpDir => { - string testPath = Path.Combine (TI.FindSourceDirectory (), @"Today/TodayExtensionTest.csproj"); - TI.BuildProject (testPath, isUnified: true); + TI.CopyDirectory (Path.Combine (TI.FindSourceDirectory (), @"Today"), tmpDir); + string project = Path.Combine (tmpDir, "Today/TodayExtensionTest.csproj"); + string main = Path.Combine (tmpDir, "Today/TodayViewController.cs"); + TI.CopyFileWithSubstitutions (project, project, s => s.Replace ("%ITEMGROUP%", "")); + TI.CopyFileWithSubstitutions (main, main, s => s.Replace ("%TESTCODE%", "")); + TI.BuildProject (project, isUnified: true); }); } @@ -33,8 +37,8 @@ public void FinderExtension_SmokeTest () MMPTests.RunMMPTest (tmpDir => { - string testPath = Path.Combine (TI.FindSourceDirectory (), @"Finder/FinderExtensionTest.csproj"); - TI.BuildProject (testPath, isUnified: true); + TI.CopyDirectory (Path.Combine (TI.FindSourceDirectory (), @"Finder"), tmpDir); + TI.BuildProject (Path.Combine (tmpDir, "Finder/FinderExtensionTest.csproj"), isUnified: true); }); } @@ -46,8 +50,8 @@ public void ShareExtension_SmokeTest () MMPTests.RunMMPTest (tmpDir => { - string testPath = Path.Combine (TI.FindSourceDirectory (), @"Share/ShareExtensionTest.csproj"); - TI.BuildProject (testPath, isUnified: true); + TI.CopyDirectory (Path.Combine (TI.FindSourceDirectory (), @"Share"), tmpDir); + TI.BuildProject (Path.Combine (tmpDir, "Share/ShareExtensionTest.csproj"), isUnified: true); }); } } diff --git a/tests/mmptest/src/PackageReferenceTests.cs b/tests/mmptest/src/PackageReferenceTests.cs new file mode 100644 index 000000000000..25e534496619 --- /dev/null +++ b/tests/mmptest/src/PackageReferenceTests.cs @@ -0,0 +1,52 @@ +using System; +using System.IO; +using System.Linq; +using NUnit.Framework; + +namespace Xamarin.MMP.Tests +{ + [TestFixture] + public class PackageReferenceTests + { + const string PackageReference = @""; + const string TestCode = @"var output = Newtonsoft.Json.JsonConvert.SerializeObject (new int[] { 1, 2, 3 });"; + + // [TestCase (true)] https://github.com/xamarin/xamarin-macios/issues/4110 + // [TestCase (false)] https://github.com/xamarin/xamarin-macios/issues/4110 + public void AppsWithPackageReferencs_BuildAndRun (bool full) + { + MMPTests.RunMMPTest (tmpDir => { + var config = new TI.UnifiedTestConfig (tmpDir) { + ItemGroup = PackageReference, + TestCode = TestCode + @" if (output == ""[1,2,3]"") + ", + XM45 = full + }; + TI.AddGUIDTestCode (config); + + string project = TI.GenerateUnifiedExecutableProject (config); + TI.NugetRestore (project); + TI.BuildProject (project, true, useMSBuild: true); + TI.RunGeneratedUnifiedExecutable (config); + }); + } + + // [Test] https://github.com/xamarin/xamarin-macios/issues/4110 + public void ExtensionProjectPackageReferencs_Build () + { + MMPTests.RunMMPTest (tmpDir => { + TI.CopyDirectory (Path.Combine (TI.FindSourceDirectory (), @"Today"), tmpDir); + + string project = Path.Combine (tmpDir, "Today/TodayExtensionTest.csproj"); + string main = Path.Combine (tmpDir, "Today/TodayViewController.cs"); + + TI.CopyFileWithSubstitutions (project, project, s => s.Replace ("%ITEMGROUP%", PackageReference)); + TI.CopyFileWithSubstitutions (main, main, s => s.Replace ("%TESTCODE%", TestCode)); + + TI.NugetRestore (project); + string output = TI.BuildProject (Path.Combine (tmpDir, "Today/TodayExtensionTest.csproj"), isUnified: true, useMSBuild: true); + Assert.IsTrue (!output.Contains ("MM2013")); + }); + } + } +}