From 00444d1507d3707f606c02f6644b40efc10f1583 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 1 Oct 2024 16:20:23 +0200 Subject: [PATCH 1/4] [msbuild] Don't try to look for library resources to unpack from BCL assemblies. Fixes #19511. (#21305) We know BCL won't have library resources to unpack, so there's no need to spend any time looking at them. This also required porting the UnpackLibraryResources task to use System.Reflection.Metadata, because MetadataLoadContext requires the reference assemblies to be available to resolve assembly dependencies (and the idea is to not have to pass any reference assemblies to the task). Fixes https://github.com/xamarin/xamarin-macios/issues/19511. Fixes https://github.com/xamarin/xamarin-macios/issues/15030. --- .../Tasks/UnpackLibraryResources.cs | 153 +++++++++--------- msbuild/Xamarin.Shared/Xamarin.Shared.targets | 6 +- 2 files changed, 78 insertions(+), 81 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/UnpackLibraryResources.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/UnpackLibraryResources.cs index 52c9b5357cd7..8c6d713e2e2a 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/UnpackLibraryResources.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/UnpackLibraryResources.cs @@ -2,6 +2,8 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; using System.Text; using System.Collections.Generic; @@ -15,7 +17,6 @@ namespace Xamarin.MacDev.Tasks { public class UnpackLibraryResources : XamarinTask, ITaskCallback, ICancelableTask { - MetadataLoadContext? universe; List unpackedResources = new List (); #region Inputs @@ -26,9 +27,6 @@ public class UnpackLibraryResources : XamarinTask, ITaskCallback, ICancelableTas [Required] public string IntermediateOutputPath { get; set; } = string.Empty; - [Required] - public ITaskItem [] ReferenceAssemblies { get; set; } = Array.Empty (); - [Required] public ITaskItem [] ReferencedLibraries { get; set; } = Array.Empty (); @@ -52,15 +50,6 @@ public class UnpackLibraryResources : XamarinTask, ITaskCallback, ICancelableTas #endregion public override bool Execute () - { - try { - return ExecuteImpl (); - } finally { - universe?.Dispose (); - } - } - - bool ExecuteImpl () { if (ShouldExecuteRemotely ()) { var result = new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result; @@ -87,7 +76,7 @@ bool ExecuteImpl () Log.LogMessage (MessageImportance.Low, MSBStrings.M0168, asm.ItemSpec); } else { var perAssemblyOutputPath = Path.Combine (IntermediateOutputPath, "unpack", asm.GetMetadata ("Filename")); - var extracted = ExtractContentAssembly (asm.ItemSpec, perAssemblyOutputPath).ToArray (); + var extracted = ExtractContentAssembly (asm.ItemSpec, perAssemblyOutputPath); results.AddRange (extracted); @@ -113,58 +102,88 @@ bool IsFrameworkAssembly (ITaskItem asm) return false; } - IEnumerable ExtractContentAssembly (string assembly, string intermediatePath) + List ExtractContentAssembly (string assembly, string intermediatePath) { + var rv = new List (); + if (!File.Exists (assembly)) { Log.LogMessage (MessageImportance.Low, $"Not inspecting assembly because it doesn't exist: {assembly}"); - yield break; + return rv; } - var asmWriteTime = File.GetLastWriteTimeUtc (assembly); - var manifestResources = GetAssemblyManifestResources (assembly).ToArray (); - if (!manifestResources.Any ()) - yield break; - - Log.LogMessage (MessageImportance.Low, $"Inspecting assembly with {manifestResources.Length} resources: {assembly}"); - foreach (var embedded in manifestResources) { - string rpath; - - if (embedded.Name.StartsWith ("__" + Prefix + "_content_", StringComparison.Ordinal)) { - var mangled = embedded.Name.Substring (("__" + Prefix + "_content_").Length); - rpath = UnmangleResource (mangled); - } else if (embedded.Name.StartsWith ("__" + Prefix + "_page_", StringComparison.Ordinal)) { - var mangled = embedded.Name.Substring (("__" + Prefix + "_page_").Length); - rpath = UnmangleResource (mangled); - } else { - continue; - } - - var path = Path.Combine (intermediatePath, rpath); - var file = new FileInfo (path); - - var item = new TaskItem (path); - item.SetMetadata ("LogicalName", rpath); - item.SetMetadata ("Optimize", "false"); - - if (file.Exists && file.LastWriteTimeUtc >= asmWriteTime) { - Log.LogMessage (" Up to date: {0}", rpath); - } else { - Log.LogMessage (" Unpacking: {0}", rpath); - - Directory.CreateDirectory (Path.GetDirectoryName (path)); + try { + var asmWriteTime = File.GetLastWriteTimeUtc (assembly); + using var peStream = File.OpenRead (assembly); + using var peReader = new PEReader (peStream); + var metadataReader = PEReaderExtensions.GetMetadataReader (peReader); + Log.LogMessage (MessageImportance.Low, $"Inspecting resources in assembly {assembly}"); + foreach (var manifestResourceHandle in metadataReader.ManifestResources) { + var manifestResource = metadataReader.GetManifestResource (manifestResourceHandle); + if (!manifestResource.Implementation.IsNil) + continue; // embedded resources have Implementation.IsNil = true, and those are the ones we care about + + var name = metadataReader.GetString (manifestResource.Name); + if (string.IsNullOrEmpty (name)) + continue; + + string rpath; + + if (name.StartsWith ("__" + Prefix + "_content_", StringComparison.Ordinal)) { + var mangled = name.Substring (("__" + Prefix + "_content_").Length); + rpath = UnmangleResource (mangled); + } else if (name.StartsWith ("__" + Prefix + "_page_", StringComparison.Ordinal)) { + var mangled = name.Substring (("__" + Prefix + "_page_").Length); + rpath = UnmangleResource (mangled); + } else { + continue; + } - using (var stream = File.Open (path, FileMode.Create)) { - using (var resource = embedded.Open ()) - resource.CopyTo (stream); + var path = Path.Combine (intermediatePath, rpath); + var file = new FileInfo (path); + + var item = new TaskItem (path); + item.SetMetadata ("LogicalName", rpath); + item.SetMetadata ("Optimize", "false"); + + if (file.Exists && file.LastWriteTimeUtc >= asmWriteTime) { + Log.LogMessage (" Up to date: {0}", rpath); + } else { + Log.LogMessage (" Unpacking: {0}", rpath); + + Directory.CreateDirectory (Path.GetDirectoryName (path)); + + var resourceDirectory = peReader.GetSectionData (peReader.PEHeaders.CorHeader!.ResourcesDirectory.RelativeVirtualAddress); + var reader = resourceDirectory.GetReader ((int) manifestResource.Offset, resourceDirectory.Length - (int) manifestResource.Offset); + var length = reader.ReadUInt32 (); + if (length > reader.RemainingBytes) + throw new BadImageFormatException (); +#if NET + using var fs = new FileStream (path, FileMode.Create, FileAccess.Write, FileShare.Read); + unsafe { + var span = new ReadOnlySpan (reader.CurrentPointer, (int) length); + fs.Write (span); + } +#else + var buffer = new byte [4096]; + using var fs = new FileStream (path, FileMode.Create, FileAccess.Write, FileShare.Read, buffer.Length); + var left = (int) length; + while (left > 0) { + var read = Math.Min (left, buffer.Length); + reader.ReadBytes (read, buffer, 0); + fs.Write (buffer, 0, read); + left -= read; + } +#endif + unpackedResources.Add (item); } - unpackedResources.Add (item); + rv.Add (item); } - - yield return item; + } catch (Exception e) { + Log.LogMessage (MessageImportance.Low, $"Unable to load the resources from the assembly '{assembly}': {e}"); + return new List (); } - - yield break; + return rv; } static string UnmangleResource (string mangled) @@ -237,27 +256,5 @@ public bool ShouldCopyToBuildServer (ITaskItem item) public IEnumerable GetAdditionalItemsToBeCopied () => ItemsFiles; - IEnumerable GetAssemblyManifestResources (string fileName) - { - if (universe is null) - universe = new MetadataLoadContext (new PathAssemblyResolver (ReferenceAssemblies.Select (v => v.ItemSpec))); - - Assembly assembly; - try { - assembly = universe.LoadFromAssemblyPath (fileName); - } catch (Exception e) { - Log.LogMessage (MessageImportance.Low, $"Unable to load the assembly '{fileName}: {e}"); - yield break; - } - - foreach (var resourceName in assembly.GetManifestResourceNames ()) { - if (string.IsNullOrEmpty (resourceName)) - continue; - var info = assembly.GetManifestResourceInfo (resourceName); - if (!info.ResourceLocation.HasFlag (ResourceLocation.Embedded)) - continue; - yield return new ManifestResource (resourceName, () => assembly.GetManifestResourceStream (resourceName)); - } - } } } diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index 22556e3f38f0..b9e1388c9667 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -1933,7 +1933,9 @@ Copyright (C) 2018 Microsoft. All rights reserved. <_StampDirectory>$(DeviceSpecificIntermediateOutputPath)resourcestamps\ - <_UnpackLibraryResourceItems Include="@(ReferencePath);@(ReferenceDependencyPaths)"> + <_UnpackLibraryResourceItems Include="@(ReferencePath)" Condition="'%(ReferencePath.FrameworkReferenceName)' != 'Microsoft.NETCore.App' And '%(ReferencePath.FrameworkReferenceName)' != 'Microsoft.$(_PlatformName)'" /> + <_UnpackLibraryResourceItems Include="@(ReferenceDependencyPaths)" Condition="'%(ReferenceDependencyPaths.FrameworkReferenceName)' != 'Microsoft.NETCore.App' And '%(ReferenceDependencyPaths.FrameworkReferenceName)' != 'Microsoft.$(_PlatformName)'" /> + <_UnpackLibraryResourceItems> $(_StampDirectory)%(FileName).stamp $(_StampDirectory)%(FileName).items @@ -1982,14 +1984,12 @@ Copyright (C) 2018 Microsoft. All rights reserved. - From 15c1e7527e8d621760b9fe2c6b1ce2382dcab2f7 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 1 Oct 2024 17:54:27 +0200 Subject: [PATCH 2/4] [msbuild/tests] Use 'dotnet test' for the MSBuild tests. (#21263) This is another step towards removing Mono. This required a few changes: * Nullability updates in test code. * Explicitly sorted list of strings in a warning message, to make the warning text stable. * Stopped merging system assemblies in the merged tasks assembly. This was necessary for to solve a problem with duplicate types: * The netstandard2.0 version of `System.Reflection.Metadata.dll` contains the `UnconditionalSuppressMessageAttribute` type (internally). * Since we ILMerge the tasks assembly, this type ends up in Xamarin.iOS.Tasks.dll (internally). * The test assembly can't be a net472 assembly, because that means using the netfx/desktop versions of the Microsoft.Build.* assemblies, which don't work on .NET (they check for Mono, but .NET isn't Mono, so the check fails and a PlatformNotSupportedException is thrown). * So I bumped the test assembly to be a net8.0 assembly, but then there's a conflict between the `UnconditionalSuppressMessageAttribute` shipped in .NET vs the one in `Xamarin.iOS.Tasks.dll` (because the test assembly can see the internals of `Xamarin.iOS.Tasks.dll`). * The fix that seems to work is to *not* merge system assemblies in the `Xamarin.iOS.Tasks.dll` assembly. `Xamarin.iOS.Tasks.Windows.dll` already does this, so hopefully there are no problems on Windows, and on macOS our tests doesn't reveal any problems. --- msbuild/ILMerge.targets | 2 +- .../Tasks/ComputeCodesignItems.cs | 2 +- tests/Makefile | 12 +++++--- .../TaskTests/CompileAppManifestTaskTests.cs | 4 +-- .../TaskTests/CompileEntitlementsTaskTests.cs | 4 +-- .../ComputeCodesignItemsTaskTests.cs | 8 +++--- .../ResolveNativeReferencesTaskTest.cs | 4 +-- .../Xamarin.MacDev.Tasks.Tests.csproj | 14 +++++----- .../TestHelpers/BuildEngine.cs | 2 +- .../Xamarin.MacDev.Tests.csproj | 6 ++-- .../Jenkins/NUnitTestTasksEnumerable.cs | 28 ++++++++----------- 11 files changed, 42 insertions(+), 44 deletions(-) diff --git a/msbuild/ILMerge.targets b/msbuild/ILMerge.targets index 35ff9af16f5b..a0885f68751b 100644 --- a/msbuild/ILMerge.targets +++ b/msbuild/ILMerge.targets @@ -2,7 +2,7 @@ true - true + false diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs index 085e9f067b25..c001208bcb51 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs @@ -161,7 +161,7 @@ public override bool Execute () for (var i = 1; i < all.Length; i++) { var nextMetadata = all [i].CloneCustomMetadataToDictionary (); if (nextMetadata.Count != firstMetadata.Count) { - Log.LogWarning (MSBStrings.W7095, /* Code signing has been requested multiple times for '{0}', with different metadata. The metadata for one are: '{1}', while the metadata for the other are: '{2}' */ group.Key, string.Join (", ", firstMetadata.Keys), string.Join (", ", nextMetadata.Keys)); + Log.LogWarning (MSBStrings.W7095, /* Code signing has been requested multiple times for '{0}', with different metadata. The metadata for one are: '{1}', while the metadata for the other are: '{2}' */ group.Key, string.Join (", ", firstMetadata.Keys.OrderBy (v => v)), string.Join (", ", nextMetadata.Keys.OrderBy (v => v))); } else { foreach (var kvp in firstMetadata) { if (!nextMetadata.TryGetValue (kvp.Key, out var nextValue)) { diff --git a/tests/Makefile b/tests/Makefile index 917286623b74..1e0462c77aa9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -217,15 +217,19 @@ killall: NUNIT_MSBUILD_DIR=$(TOP)/packages/NUnit.Runners.2.6.4/tools/lib test-ios-tasks: test-macdev-tests test-macdev-tasks +# Example TEST_FILTER: +# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" +# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tests: export MSBUILD_EXE_PATH= test-macdev-tests: verify-system-vsmac-xcode-match - $(Q) $(DOTNET) build "/bl:$@.binlog" $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj /p:Configuration=Debug $(DOTNET_BUILD_VERBOSITY) - cd $(TOP)/tests/msbuild/Xamarin.MacDev.Tests && $(SYSTEM_XIBUILD) -t -- $(abspath $(TOP)/tools/nunit3-console-3.11.1) $(abspath $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/bin/Debug/net472/Xamarin.MacDev.Tests.dll) "--result=$(abspath $(CURDIR)/TestResults_Xamarin.MacDev.Tests.xml);format=nunit2" -labels=After $(TEST_FIXTURE) + $(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj $(TEST_FILTER) +# Example TEST_FILTER: +# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" +# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tasks: export MSBUILD_EXE_PATH= test-macdev-tasks: verify-system-vsmac-xcode-match - $(Q) $(DOTNET) build "/bl:$@.binlog" $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj /p:Configuration=Debug $(DOTNET_BUILD_VERBOSITY) - cd $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests && $(SYSTEM_XIBUILD) -t -- $(abspath $(TOP)/tools/nunit3-console-3.11.1) $(abspath $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/bin/Debug/net472/Xamarin.MacDev.Tasks.Tests.dll) "--result=$(abspath $(CURDIR)/TestResults_Xamarin.MacDev.Tasks.Tests.xml)" -labels=After $(TEST_FIXTURE) + $(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj $(TEST_FILTER) mac-test-package.zip: ifdef INCLUDE_MAC diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs index 94463d1d8ab1..00c3fa08f935 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs @@ -21,8 +21,8 @@ CompileAppManifest CreateTask (string? tmpdir = null, ApplePlatform platform = A task.AssemblyName = "AssemblyName"; task.AppBundleName = "AppBundleName"; task.CompiledAppManifest = new TaskItem (Path.Combine (tmpdir, "TemporaryAppManifest.plist")); - task.DefaultSdkVersion = Sdks.GetAppleSdk (platform).GetInstalledSdkVersions (false).First ().ToString (); - task.SdkVersion = task.DefaultSdkVersion; + task.DefaultSdkVersion = Sdks.GetAppleSdk (platform).GetInstalledSdkVersions (false).First ().ToString ()!; + task.SdkVersion = task.DefaultSdkVersion ?? string.Empty; task.TargetFrameworkMoniker = TargetFramework.GetTargetFramework (platform, true).ToString (); return task; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs index 00c90fc9d9a1..17186c306f29 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs @@ -34,8 +34,8 @@ CustomCompileEntitlements CreateEntitlementsTask (out string compiledEntitlement task.AppBundleDir = AppBundlePath; task.BundleIdentifier = "com.xamarin.MySingleView"; task.CompiledEntitlements = new TaskItem (Path.Combine (MonoTouchProjectObjPath, "Entitlements.xcent")); - task.Entitlements = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "Entitlements.plist"); - task.ProvisioningProfile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "profile.mobileprovision"); + task.Entitlements = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "Entitlements.plist"); + task.ProvisioningProfile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "profile.mobileprovision"); task.SdkPlatform = "iPhoneOS"; task.SdkVersion = "6.1"; task.TargetFrameworkMoniker = "Xamarin.iOS,v1.0"; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs index 9255a818a2fc..d72eecdb893b 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs @@ -496,7 +496,7 @@ public void DuplicatedWithDifferentMetadata (ApplePlatform platform, bool isDotN Assert.AreEqual (3, Engine.Logger.WarningsEvents.Count, "Warning Count"); Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata 'OnlyIn1=true' has been set for one item, but not the other.", Engine.Logger.WarningsEvents [0].Message, "Message #0"); Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata 'InOneAndTwoWithDifferentValues' has different values for each item (once it's '1', another time it's '2').", Engine.Logger.WarningsEvents [1].Message, "Message #1"); - Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata for one are: 'RequireCodeSigning, OnlyIn1, InOneAndTwoWithDifferentValues, CodesignStampFile', while the metadata for the other are: 'RequireCodeSigning, CodesignStampFile'", Engine.Logger.WarningsEvents [2].Message, "Message #2"); + Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata for one are: 'CodesignStampFile, InOneAndTwoWithDifferentValues, OnlyIn1, RequireCodeSigning', while the metadata for the other are: 'CodesignStampFile, RequireCodeSigning'", Engine.Logger.WarningsEvents [2].Message, "Message #2"); VerifyCodesigningResults (infos, task.OutputCodesignItems, platform); } finally { @@ -532,7 +532,7 @@ void VerifyCodesigningResults (CodesignInfo [] infos, ITaskItem [] outputCodesig var metadata = item.GetMetadata (kvp.Key); if (metadata == string.Empty && kvp.Value != string.Empty) { failures.Add ($"Item '{info.ItemSpec}': Expected metadata '{kvp.Key}' not found (with value '{kvp.Value}')."); - } else if (!string.Equals (metadata, kvp.Value)) { + } else if (!string.Equals (metadata, kvp.Value, StringComparison.Ordinal)) { failures.Add ($"Item '{info.ItemSpec}': Expected value '{kvp.Value}' for metadata '{kvp.Key}', but got '{metadata}' instead.\nExpected: {kvp.Value}\nActual: {metadata}"); } } @@ -587,7 +587,7 @@ void Touch (string root, params string [] files) if (file.EndsWith (".appex", StringComparison.OrdinalIgnoreCase) || file.EndsWith (".app", StringComparison.OrdinalIgnoreCase)) { Directory.CreateDirectory (f); } else { - Directory.CreateDirectory (Path.GetDirectoryName (file)); + Directory.CreateDirectory (Path.GetDirectoryName (file)!); File.WriteAllText (file, string.Empty); } } @@ -637,7 +637,7 @@ public static Dictionary CopyCustomMetadata (this ITaskItem self { var rv = new Dictionary (); foreach (DictionaryEntry de in self.CloneCustomMetadata ()) { - rv [(string) de.Key] = (string) de.Value; + rv [(string) de.Key!] = (string) de.Value!; } return rv; } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs index 838d1be627ce..148849779358 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs @@ -38,7 +38,7 @@ public void Xcode12_x (string targetFrameworkMoniker, bool isSimulator, string a // some architecture changes recently, e.g. // in Xcode 12.1+ watchOS does not have an i386 architecture anymore // on Xcode 12.2+ you get arm64 for all (iOS, tvOS and watchOS) simulators - var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-xcode12.2.plist"); + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "xcf-xcode12.2.plist"); var plist = PDictionary.FromFile (path)!; var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath); Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result"); @@ -51,7 +51,7 @@ public void Xcode12_x (string targetFrameworkMoniker, bool isSimulator, string a [TestCase (TargetFramework.Xamarin_WatchOS_1_0_String, true, "i386", "watchos-i386-simulator/XTest.framework/XTest")] public void PreXcode12 (string targetFrameworkMoniker, bool isSimulator, string architecture, string expected) { - var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-prexcode12.plist"); + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "xcf-prexcode12.plist"); var plist = PDictionary.FromFile (path)!; var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath); Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result"); diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj index 126d96deee76..a01b20140e75 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj @@ -1,7 +1,7 @@ - net472 + net$(BundledNETCoreAppTargetFrameworkVersion) false true latest @@ -32,12 +32,12 @@ - - - - - - + + + + + + diff --git a/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs b/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs index 59b130f99d1d..8043c1875436 100644 --- a/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs +++ b/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs @@ -246,7 +246,7 @@ static ExecutionResult MSBuild (ApplePlatform platform, string project, string t foreach (var prop in properties) args.Add ($"/p:{prop.Key}={prop.Value}"); } - var binlog = Path.Combine (Path.GetDirectoryName (project), $"log-{target}-{DateTime.Now:yyyyMMdd_HHmmss}.binlog"); + var binlog = Path.Combine (Path.GetDirectoryName (project)!, $"log-{target}-{DateTime.Now:yyyyMMdd_HHmmss}.binlog"); args.Add ($"/bl:{binlog}"); var output = new StringBuilder (); diff --git a/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj b/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj index 87ff4869076f..771e95f8bcb2 100644 --- a/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj +++ b/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj @@ -1,7 +1,7 @@ - net472 + net$(BundledNETCoreAppTargetFrameworkVersion) false true latest @@ -11,8 +11,8 @@ - - + + diff --git a/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs b/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs index 8b807022b6ac..bc991bce25c2 100644 --- a/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs +++ b/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs @@ -19,27 +19,24 @@ public NUnitTestTasksEnumerable (Jenkins jenkins, IMlaunchProcessManager process public IEnumerator GetEnumerator () { - var netstandard2Project = new TestProject (TestLabel.Msbuild, Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "Xamarin.MacDev.Tasks.Tests.csproj"))) { + var msbuildTasksTestsProject = new TestProject (TestLabel.Msbuild, Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "Xamarin.MacDev.Tasks.Tests.csproj"))) { IsDotNetProject = true, }; var env = new Dictionary { { "SYSTEM_MONO", this.jenkins.Harness.SYSTEM_MONO }, }; - var buildiOSMSBuild = new MSBuildTask (jenkins: jenkins, testProject: netstandard2Project, processManager: processManager) { + var buildiOSMSBuild = new MSBuildTask (jenkins: jenkins, testProject: msbuildTasksTestsProject, processManager: processManager) { SpecifyPlatform = false, - SpecifyConfiguration = true, ProjectConfiguration = "Debug", - Platform = TestPlatform.iOS, - SolutionPath = Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")), + Platform = TestPlatform.All, + Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Msbuild), SupportsParallelExecution = false, - Environment = env, }; - var nunitExecutioniOSMSBuild = new NUnitExecuteTask (jenkins, buildiOSMSBuild, processManager) { - TestLibrary = Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "bin", "Debug", "net472", "Xamarin.MacDev.Tasks.Tests.dll"), - TestProject = netstandard2Project, + var nunitExecutioniOSMSBuild = new DotNetTestTask (jenkins, buildiOSMSBuild, processManager) { + TestProject = msbuildTasksTestsProject, ProjectConfiguration = "Debug", - Platform = TestPlatform.iOS, + Platform = TestPlatform.All, TestName = "MSBuild tests", Mode = "Tasks", Timeout = TimeSpan.FromMinutes (60), @@ -53,18 +50,15 @@ public IEnumerator GetEnumerator () }; var buildiOSMSBuildIntegration = new MSBuildTask (jenkins: jenkins, testProject: msbuildIntegrationTestsProject, processManager: processManager) { SpecifyPlatform = false, - SpecifyConfiguration = true, ProjectConfiguration = "Debug", - Platform = TestPlatform.iOS, - SolutionPath = Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")), + Platform = TestPlatform.All, + Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Msbuild), SupportsParallelExecution = false, - Environment = env, }; - var nunitExecutioniOSMSBuildIntegration = new NUnitExecuteTask (jenkins, buildiOSMSBuildIntegration, processManager) { - TestLibrary = Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tests", "bin", "Debug", "net472", "Xamarin.MacDev.Tests.dll"), + var nunitExecutioniOSMSBuildIntegration = new DotNetTestTask (jenkins, buildiOSMSBuildIntegration, processManager) { TestProject = msbuildIntegrationTestsProject, ProjectConfiguration = "Debug", - Platform = TestPlatform.iOS, + Platform = TestPlatform.All, TestName = "MSBuild tests", Mode = "Integration", Timeout = TimeSpan.FromMinutes (120), From 5a0d412c87de5e55e00303ca6fd99d63341c8cf9 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Tue, 1 Oct 2024 15:42:37 -0400 Subject: [PATCH 3/4] [CI] Use the full path for triggering resources. (#21338) VSTS recommends this in their docs. We are going to do it to make it simpler to track what triggers what. --- tools/devops/automation/run-post-ci-build-macos-tests.yml | 2 +- tools/devops/automation/run-post-ci-build-tests.yml | 3 +-- tools/devops/automation/run-post-pr-build-macos-tests.yml | 2 +- tools/devops/automation/run-post-pr-build-tests.yml | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/devops/automation/run-post-ci-build-macos-tests.yml b/tools/devops/automation/run-post-ci-build-macos-tests.yml index bbdb367de5d7..da312f9e6997 100644 --- a/tools/devops/automation/run-post-ci-build-macos-tests.yml +++ b/tools/devops/automation/run-post-ci-build-macos-tests.yml @@ -9,7 +9,7 @@ pr: none resources: pipelines: - pipeline: macios - source: xamarin-macios-ci + source: \Xamarin\Mac-iOS\ci pipelines\xamarin-macios-ci trigger: stages: - build_macos_tests diff --git a/tools/devops/automation/run-post-ci-build-tests.yml b/tools/devops/automation/run-post-ci-build-tests.yml index 5ffbfa0917f6..af8677d8b4e6 100644 --- a/tools/devops/automation/run-post-ci-build-tests.yml +++ b/tools/devops/automation/run-post-ci-build-tests.yml @@ -4,12 +4,11 @@ trigger: none pr: none - # we cannot use a template in a pipeline context resources: pipelines: - pipeline: macios - source: xamarin-macios-ci + source: \Xamarin\Mac-iOS\ci pipelines\xamarin-macios-ci trigger: stages: - build_packages diff --git a/tools/devops/automation/run-post-pr-build-macos-tests.yml b/tools/devops/automation/run-post-pr-build-macos-tests.yml index e324fe5d8b3e..fdda5ca9e088 100644 --- a/tools/devops/automation/run-post-pr-build-macos-tests.yml +++ b/tools/devops/automation/run-post-pr-build-macos-tests.yml @@ -8,7 +8,7 @@ pr: none resources: pipelines: - pipeline: macios - source: xamarin-macios-pr + source: \Xamarin\Mac-iOS\pr pipelines\xamarin-macios-pr trigger: stages: - build_macos_tests diff --git a/tools/devops/automation/run-post-pr-build-tests.yml b/tools/devops/automation/run-post-pr-build-tests.yml index 45a676699994..16bdd59d45bd 100644 --- a/tools/devops/automation/run-post-pr-build-tests.yml +++ b/tools/devops/automation/run-post-pr-build-tests.yml @@ -8,7 +8,7 @@ pr: none resources: pipelines: - pipeline: macios - source: xamarin-macios-pr + source: \Xamarin\Mac-iOS\pr pipelines\xamarin-macios-pr trigger: stages: - build_packages From abcec04b752f26a130498db289d4d67a6c2b8f97 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 2 Oct 2024 19:51:31 +0200 Subject: [PATCH 4/4] Revert "[msbuild/tests] Use 'dotnet test' for the MSBuild tests. (#21263)" (#21356) This reverts commit 15c1e7527e8d621760b9fe2c6b1ce2382dcab2f7. It breaks the Windows tests. --- msbuild/ILMerge.targets | 2 +- .../Tasks/ComputeCodesignItems.cs | 2 +- tests/Makefile | 12 +++----- .../TaskTests/CompileAppManifestTaskTests.cs | 4 +-- .../TaskTests/CompileEntitlementsTaskTests.cs | 4 +-- .../ComputeCodesignItemsTaskTests.cs | 8 +++--- .../ResolveNativeReferencesTaskTest.cs | 4 +-- .../Xamarin.MacDev.Tasks.Tests.csproj | 14 +++++----- .../TestHelpers/BuildEngine.cs | 2 +- .../Xamarin.MacDev.Tests.csproj | 6 ++-- .../Jenkins/NUnitTestTasksEnumerable.cs | 28 +++++++++++-------- 11 files changed, 44 insertions(+), 42 deletions(-) diff --git a/msbuild/ILMerge.targets b/msbuild/ILMerge.targets index a0885f68751b..35ff9af16f5b 100644 --- a/msbuild/ILMerge.targets +++ b/msbuild/ILMerge.targets @@ -2,7 +2,7 @@ true - false + true diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs index c001208bcb51..085e9f067b25 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/ComputeCodesignItems.cs @@ -161,7 +161,7 @@ public override bool Execute () for (var i = 1; i < all.Length; i++) { var nextMetadata = all [i].CloneCustomMetadataToDictionary (); if (nextMetadata.Count != firstMetadata.Count) { - Log.LogWarning (MSBStrings.W7095, /* Code signing has been requested multiple times for '{0}', with different metadata. The metadata for one are: '{1}', while the metadata for the other are: '{2}' */ group.Key, string.Join (", ", firstMetadata.Keys.OrderBy (v => v)), string.Join (", ", nextMetadata.Keys.OrderBy (v => v))); + Log.LogWarning (MSBStrings.W7095, /* Code signing has been requested multiple times for '{0}', with different metadata. The metadata for one are: '{1}', while the metadata for the other are: '{2}' */ group.Key, string.Join (", ", firstMetadata.Keys), string.Join (", ", nextMetadata.Keys)); } else { foreach (var kvp in firstMetadata) { if (!nextMetadata.TryGetValue (kvp.Key, out var nextValue)) { diff --git a/tests/Makefile b/tests/Makefile index 1e0462c77aa9..917286623b74 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -217,19 +217,15 @@ killall: NUNIT_MSBUILD_DIR=$(TOP)/packages/NUnit.Runners.2.6.4/tools/lib test-ios-tasks: test-macdev-tests test-macdev-tasks -# Example TEST_FILTER: -# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" -# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tests: export MSBUILD_EXE_PATH= test-macdev-tests: verify-system-vsmac-xcode-match - $(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj $(TEST_FILTER) + $(Q) $(DOTNET) build "/bl:$@.binlog" $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj /p:Configuration=Debug $(DOTNET_BUILD_VERBOSITY) + cd $(TOP)/tests/msbuild/Xamarin.MacDev.Tests && $(SYSTEM_XIBUILD) -t -- $(abspath $(TOP)/tools/nunit3-console-3.11.1) $(abspath $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/bin/Debug/net472/Xamarin.MacDev.Tests.dll) "--result=$(abspath $(CURDIR)/TestResults_Xamarin.MacDev.Tests.xml);format=nunit2" -labels=After $(TEST_FIXTURE) -# Example TEST_FILTER: -# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" -# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tasks: export MSBUILD_EXE_PATH= test-macdev-tasks: verify-system-vsmac-xcode-match - $(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj $(TEST_FILTER) + $(Q) $(DOTNET) build "/bl:$@.binlog" $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj /p:Configuration=Debug $(DOTNET_BUILD_VERBOSITY) + cd $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests && $(SYSTEM_XIBUILD) -t -- $(abspath $(TOP)/tools/nunit3-console-3.11.1) $(abspath $(TOP)/tests/msbuild/Xamarin.MacDev.Tasks.Tests/bin/Debug/net472/Xamarin.MacDev.Tasks.Tests.dll) "--result=$(abspath $(CURDIR)/TestResults_Xamarin.MacDev.Tasks.Tests.xml)" -labels=After $(TEST_FIXTURE) mac-test-package.zip: ifdef INCLUDE_MAC diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs index 00c3fa08f935..94463d1d8ab1 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileAppManifestTaskTests.cs @@ -21,8 +21,8 @@ CompileAppManifest CreateTask (string? tmpdir = null, ApplePlatform platform = A task.AssemblyName = "AssemblyName"; task.AppBundleName = "AppBundleName"; task.CompiledAppManifest = new TaskItem (Path.Combine (tmpdir, "TemporaryAppManifest.plist")); - task.DefaultSdkVersion = Sdks.GetAppleSdk (platform).GetInstalledSdkVersions (false).First ().ToString ()!; - task.SdkVersion = task.DefaultSdkVersion ?? string.Empty; + task.DefaultSdkVersion = Sdks.GetAppleSdk (platform).GetInstalledSdkVersions (false).First ().ToString (); + task.SdkVersion = task.DefaultSdkVersion; task.TargetFrameworkMoniker = TargetFramework.GetTargetFramework (platform, true).ToString (); return task; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs index 17186c306f29..00c90fc9d9a1 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/CompileEntitlementsTaskTests.cs @@ -34,8 +34,8 @@ CustomCompileEntitlements CreateEntitlementsTask (out string compiledEntitlement task.AppBundleDir = AppBundlePath; task.BundleIdentifier = "com.xamarin.MySingleView"; task.CompiledEntitlements = new TaskItem (Path.Combine (MonoTouchProjectObjPath, "Entitlements.xcent")); - task.Entitlements = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "Entitlements.plist"); - task.ProvisioningProfile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "profile.mobileprovision"); + task.Entitlements = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "Entitlements.plist"); + task.ProvisioningProfile = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "profile.mobileprovision"); task.SdkPlatform = "iPhoneOS"; task.SdkVersion = "6.1"; task.TargetFrameworkMoniker = "Xamarin.iOS,v1.0"; diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs index d72eecdb893b..9255a818a2fc 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ComputeCodesignItemsTaskTests.cs @@ -496,7 +496,7 @@ public void DuplicatedWithDifferentMetadata (ApplePlatform platform, bool isDotN Assert.AreEqual (3, Engine.Logger.WarningsEvents.Count, "Warning Count"); Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata 'OnlyIn1=true' has been set for one item, but not the other.", Engine.Logger.WarningsEvents [0].Message, "Message #0"); Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata 'InOneAndTwoWithDifferentValues' has different values for each item (once it's '1', another time it's '2').", Engine.Logger.WarningsEvents [1].Message, "Message #1"); - Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata for one are: 'CodesignStampFile, InOneAndTwoWithDifferentValues, OnlyIn1, RequireCodeSigning', while the metadata for the other are: 'CodesignStampFile, RequireCodeSigning'", Engine.Logger.WarningsEvents [2].Message, "Message #2"); + Assert.AreEqual ("Code signing has been requested multiple times for 'Bundle.app/Contents/MonoBundle/createdump', with different metadata. The metadata for one are: 'RequireCodeSigning, OnlyIn1, InOneAndTwoWithDifferentValues, CodesignStampFile', while the metadata for the other are: 'RequireCodeSigning, CodesignStampFile'", Engine.Logger.WarningsEvents [2].Message, "Message #2"); VerifyCodesigningResults (infos, task.OutputCodesignItems, platform); } finally { @@ -532,7 +532,7 @@ void VerifyCodesigningResults (CodesignInfo [] infos, ITaskItem [] outputCodesig var metadata = item.GetMetadata (kvp.Key); if (metadata == string.Empty && kvp.Value != string.Empty) { failures.Add ($"Item '{info.ItemSpec}': Expected metadata '{kvp.Key}' not found (with value '{kvp.Value}')."); - } else if (!string.Equals (metadata, kvp.Value, StringComparison.Ordinal)) { + } else if (!string.Equals (metadata, kvp.Value)) { failures.Add ($"Item '{info.ItemSpec}': Expected value '{kvp.Value}' for metadata '{kvp.Key}', but got '{metadata}' instead.\nExpected: {kvp.Value}\nActual: {metadata}"); } } @@ -587,7 +587,7 @@ void Touch (string root, params string [] files) if (file.EndsWith (".appex", StringComparison.OrdinalIgnoreCase) || file.EndsWith (".app", StringComparison.OrdinalIgnoreCase)) { Directory.CreateDirectory (f); } else { - Directory.CreateDirectory (Path.GetDirectoryName (file)!); + Directory.CreateDirectory (Path.GetDirectoryName (file)); File.WriteAllText (file, string.Empty); } } @@ -637,7 +637,7 @@ public static Dictionary CopyCustomMetadata (this ITaskItem self { var rv = new Dictionary (); foreach (DictionaryEntry de in self.CloneCustomMetadata ()) { - rv [(string) de.Key!] = (string) de.Value!; + rv [(string) de.Key] = (string) de.Value; } return rv; } diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs index 148849779358..838d1be627ce 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/ResolveNativeReferencesTaskTest.cs @@ -38,7 +38,7 @@ public void Xcode12_x (string targetFrameworkMoniker, bool isSimulator, string a // some architecture changes recently, e.g. // in Xcode 12.1+ watchOS does not have an i386 architecture anymore // on Xcode 12.2+ you get arm64 for all (iOS, tvOS and watchOS) simulators - var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "xcf-xcode12.2.plist"); + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-xcode12.2.plist"); var plist = PDictionary.FromFile (path)!; var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath); Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result"); @@ -51,7 +51,7 @@ public void Xcode12_x (string targetFrameworkMoniker, bool isSimulator, string a [TestCase (TargetFramework.Xamarin_WatchOS_1_0_String, true, "i386", "watchos-i386-simulator/XTest.framework/XTest")] public void PreXcode12 (string targetFrameworkMoniker, bool isSimulator, string architecture, string expected) { - var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "xcf-prexcode12.plist"); + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-prexcode12.plist"); var plist = PDictionary.FromFile (path)!; var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath); Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result"); diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj index a01b20140e75..126d96deee76 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj @@ -1,7 +1,7 @@ - net$(BundledNETCoreAppTargetFrameworkVersion) + net472 false true latest @@ -32,12 +32,12 @@ - - - - - - + + + + + + diff --git a/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs b/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs index 8043c1875436..59b130f99d1d 100644 --- a/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs +++ b/tests/msbuild/Xamarin.MacDev.Tests/TestHelpers/BuildEngine.cs @@ -246,7 +246,7 @@ static ExecutionResult MSBuild (ApplePlatform platform, string project, string t foreach (var prop in properties) args.Add ($"/p:{prop.Key}={prop.Value}"); } - var binlog = Path.Combine (Path.GetDirectoryName (project)!, $"log-{target}-{DateTime.Now:yyyyMMdd_HHmmss}.binlog"); + var binlog = Path.Combine (Path.GetDirectoryName (project), $"log-{target}-{DateTime.Now:yyyyMMdd_HHmmss}.binlog"); args.Add ($"/bl:{binlog}"); var output = new StringBuilder (); diff --git a/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj b/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj index 771e95f8bcb2..87ff4869076f 100644 --- a/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj +++ b/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj @@ -1,7 +1,7 @@ - net$(BundledNETCoreAppTargetFrameworkVersion) + net472 false true latest @@ -11,8 +11,8 @@ - - + + diff --git a/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs b/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs index bc991bce25c2..8b807022b6ac 100644 --- a/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs +++ b/tests/xharness/Jenkins/NUnitTestTasksEnumerable.cs @@ -19,24 +19,27 @@ public NUnitTestTasksEnumerable (Jenkins jenkins, IMlaunchProcessManager process public IEnumerator GetEnumerator () { - var msbuildTasksTestsProject = new TestProject (TestLabel.Msbuild, Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "Xamarin.MacDev.Tasks.Tests.csproj"))) { + var netstandard2Project = new TestProject (TestLabel.Msbuild, Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "Xamarin.MacDev.Tasks.Tests.csproj"))) { IsDotNetProject = true, }; var env = new Dictionary { { "SYSTEM_MONO", this.jenkins.Harness.SYSTEM_MONO }, }; - var buildiOSMSBuild = new MSBuildTask (jenkins: jenkins, testProject: msbuildTasksTestsProject, processManager: processManager) { + var buildiOSMSBuild = new MSBuildTask (jenkins: jenkins, testProject: netstandard2Project, processManager: processManager) { SpecifyPlatform = false, + SpecifyConfiguration = true, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, - Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Msbuild), + Platform = TestPlatform.iOS, + SolutionPath = Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")), SupportsParallelExecution = false, + Environment = env, }; - var nunitExecutioniOSMSBuild = new DotNetTestTask (jenkins, buildiOSMSBuild, processManager) { - TestProject = msbuildTasksTestsProject, + var nunitExecutioniOSMSBuild = new NUnitExecuteTask (jenkins, buildiOSMSBuild, processManager) { + TestLibrary = Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tasks.Tests", "bin", "Debug", "net472", "Xamarin.MacDev.Tasks.Tests.dll"), + TestProject = netstandard2Project, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, + Platform = TestPlatform.iOS, TestName = "MSBuild tests", Mode = "Tasks", Timeout = TimeSpan.FromMinutes (60), @@ -50,15 +53,18 @@ public IEnumerator GetEnumerator () }; var buildiOSMSBuildIntegration = new MSBuildTask (jenkins: jenkins, testProject: msbuildIntegrationTestsProject, processManager: processManager) { SpecifyPlatform = false, + SpecifyConfiguration = true, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, - Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Msbuild), + Platform = TestPlatform.iOS, + SolutionPath = Path.GetFullPath (Path.Combine (HarnessConfiguration.RootDirectory, "..", "msbuild", "Xamarin.MacDev.Tasks.sln")), SupportsParallelExecution = false, + Environment = env, }; - var nunitExecutioniOSMSBuildIntegration = new DotNetTestTask (jenkins, buildiOSMSBuildIntegration, processManager) { + var nunitExecutioniOSMSBuildIntegration = new NUnitExecuteTask (jenkins, buildiOSMSBuildIntegration, processManager) { + TestLibrary = Path.Combine (HarnessConfiguration.RootDirectory, "msbuild", "Xamarin.MacDev.Tests", "bin", "Debug", "net472", "Xamarin.MacDev.Tests.dll"), TestProject = msbuildIntegrationTestsProject, ProjectConfiguration = "Debug", - Platform = TestPlatform.All, + Platform = TestPlatform.iOS, TestName = "MSBuild tests", Mode = "Integration", Timeout = TimeSpan.FromMinutes (120),