From 6e7266b63eeabe311555877f57f5bfb4aac51d86 Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Thu, 21 Feb 2019 14:45:51 -0600 Subject: [PATCH 1/3] [mac][msbuild] Add MigrateToNewXMTFI to convert TFI to new Xamarin.Mac.NET (opt-in) - https://github.com/xamarin/xamarin-macios/issues/5480 - Related: https://github.com/NuGet/NuGet.Client/pull/2572 To allow nuget to target XM Full we need to have a unique TFI (TargetFrameworkIdentifier). However, that's a really scary change to force, so let's opt-in for now. You can set true in your project or MigrateToNewXMTFI=true msbuild project.csproj to try it out. We can convert the opt-in to an opt-out with sufficient validation \ releases. --- .../Xamarin.Mac.Common.props | 14 +++++ tests/mmptest/mmptest.csproj | 1 + .../mmptest/src/TargetFrameworkMutateTests.cs | 58 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/mmptest/src/TargetFrameworkMutateTests.cs diff --git a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props index db23a7978d1c..8fb9d411e77a 100644 --- a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props +++ b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props @@ -26,6 +26,20 @@ Copyright (C) 2013-2014 Xamarin. All rights reserved. <_XamarinCommonPropsHasBeenImported>true + + + + Xamarin.Mac.NET + + true false diff --git a/tests/mmptest/mmptest.csproj b/tests/mmptest/mmptest.csproj index d2efabf9332b..76dfeb5f2de1 100644 --- a/tests/mmptest/mmptest.csproj +++ b/tests/mmptest/mmptest.csproj @@ -113,6 +113,7 @@ SdkVersions.cs + diff --git a/tests/mmptest/src/TargetFrameworkMutateTests.cs b/tests/mmptest/src/TargetFrameworkMutateTests.cs new file mode 100644 index 000000000000..96c36ade7c4c --- /dev/null +++ b/tests/mmptest/src/TargetFrameworkMutateTests.cs @@ -0,0 +1,58 @@ +using System; +using System.Linq; +using NUnit.Framework; +using Xamarin.Utils; + +namespace Xamarin.MMP.Tests +{ + [TestFixture] + public class TargetFrameworkMutateTests + { + public bool MatchesTFI (string expected, string buildOutput) + { + string tfiLine = buildOutput.SplitLines ().FirstOrDefault (x => x.StartsWith ("TargetFrameworkIdentifier =", StringComparison.Ordinal)); + if (tfiLine == null) + return false; + return tfiLine.Contains (expected); + } + + [TestCase (true)] + [TestCase (false)] + public void ShouldNotMutateWithoutOptInFlag (bool xm45) + { + MMPTests.RunMMPTest (tmpDir => { + TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) { + XM45 = xm45 + }; + var buildOutput = TI.TestUnifiedExecutable (test).BuildOutput; + string standardTFI = xm45 ? ".NETFramework" : "Xamarin.Mac"; + Assert.True (MatchesTFI (standardTFI, buildOutput), $"Build did not have expected TFI: {TI.PrintRedirectIfLong (buildOutput)}"); + }); + } + + [Test] + public void ShouldNotMutateModernWithOptInFlag () + { + MMPTests.RunMMPTest (tmpDir => { + TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) { + CSProjConfig = "true" + }; + var buildOutput = TI.TestUnifiedExecutable (test).BuildOutput; + Assert.True (MatchesTFI ("Xamarin.Mac", buildOutput), $"Build did not have expected TFI: {TI.PrintRedirectIfLong (buildOutput)}"); + }); + } + + [Test] + public void ShouldMutateFullWithOptInFlag () + { + MMPTests.RunMMPTest (tmpDir => { + TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) { + XM45 = true, + CSProjConfig = "true" + }; + var buildOutput = TI.TestUnifiedExecutable (test).BuildOutput; + Assert.True (MatchesTFI ("Xamarin.Mac.NET", buildOutput), $"Build did not have expected TFI: {TI.PrintRedirectIfLong (buildOutput)}"); + }); + } + } +} From c37e0207c825843a151232415130cf19317af395 Mon Sep 17 00:00:00 2001 From: Chris Hamons Date: Thu, 21 Feb 2019 14:54:49 -0600 Subject: [PATCH 2/3] Fix typo in comment --- msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props index 8fb9d411e77a..1b19358dd040 100644 --- a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props +++ b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.props @@ -30,7 +30,7 @@ Copyright (C) 2013-2014 Xamarin. All rights reserved. - + Xamarin.Mac.NET diff --git a/tests/mmptest/src/TargetFrameworkMutateTests.cs b/tests/mmptest/src/TargetFrameworkMutateTests.cs index 96c36ade7c4c..74912a241e4c 100644 --- a/tests/mmptest/src/TargetFrameworkMutateTests.cs +++ b/tests/mmptest/src/TargetFrameworkMutateTests.cs @@ -8,6 +8,8 @@ namespace Xamarin.MMP.Tests [TestFixture] public class TargetFrameworkMutateTests { + const string MigrateCSProjTag = "true"; + public bool MatchesTFI (string expected, string buildOutput) { string tfiLine = buildOutput.SplitLines ().FirstOrDefault (x => x.StartsWith ("TargetFrameworkIdentifier =", StringComparison.Ordinal)); @@ -34,9 +36,7 @@ public void ShouldNotMutateWithoutOptInFlag (bool xm45) public void ShouldNotMutateModernWithOptInFlag () { MMPTests.RunMMPTest (tmpDir => { - TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) { - CSProjConfig = "true" - }; + TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) { CSProjConfig = MigrateCSProjTag }; var buildOutput = TI.TestUnifiedExecutable (test).BuildOutput; Assert.True (MatchesTFI ("Xamarin.Mac", buildOutput), $"Build did not have expected TFI: {TI.PrintRedirectIfLong (buildOutput)}"); }); @@ -48,7 +48,7 @@ public void ShouldMutateFullWithOptInFlag () MMPTests.RunMMPTest (tmpDir => { TI.UnifiedTestConfig test = new TI.UnifiedTestConfig (tmpDir) { XM45 = true, - CSProjConfig = "true" + CSProjConfig = MigrateCSProjTag }; var buildOutput = TI.TestUnifiedExecutable (test).BuildOutput; Assert.True (MatchesTFI ("Xamarin.Mac.NET", buildOutput), $"Build did not have expected TFI: {TI.PrintRedirectIfLong (buildOutput)}");