From 1968080f747c677a3f247edb8fdbe122266ee71c Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 24 Apr 2026 10:43:49 -0500 Subject: [PATCH 1/2] [tests] Use MSTestPackageVersion in DotNetNewAndroidTest After `dotnet new androidtest` creates the template project, override the stable MSTest version with the preview version from eng/Versions.props. This ensures the test validates against the same MSTest version used by the rest of the build, while the template keeps the stable version for customers. The version is embedded as assembly metadata in MSBuildDeviceIntegration.csproj and read at runtime to update the generated .csproj before building. [tests] Enable CoreCLR in DotNetNewAndroidTest Remove the Assert.Ignore for CoreCLR runtime, enabling the test for both MonoVM and CoreCLR configurations. Fixes https://github.com/dotnet/android/issues/11174 Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/Version.Details.xml | 4 ++++ eng/Versions.props | 1 + .../Utilities/BaseTest.cs | 16 ++++++++++++++++ .../MSBuildDeviceIntegration.csproj | 7 +++++++ .../Tests/InstallAndRunTests.cs | 15 +++++++++++---- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 6b3488e5356..f7c89a7a69f 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -44,5 +44,9 @@ https://github.com/dotnet/dotnet ab01524bbb2ef1eea0ffaef161b3ef5686e8f256 + + https://github.com/microsoft/testfx + 7d4c0f051d6e8d52daaa0f7f354d57e95c475a03 + diff --git a/eng/Versions.props b/eng/Versions.props index 35b2f33059e..632fa8826da 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -15,6 +15,7 @@ $(MicrosoftNETWorkloadEmscriptenCurrentManifest110100preview4PackageVersion) 11.0.100-preview.4.26215.121 0.11.5-preview.26215.121 + 4.3.0-preview.26224.6 10.0.7 11.0.0-preview.1.26104.118 diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs index f8f78db81f5..fc5e4e3ed81 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading; using System.Xml.Linq; @@ -27,6 +28,21 @@ public class BaseTest public string Root => Path.GetFullPath (XABuildPaths.TestOutputDirectory); + /// + /// Retrieves the value of an embedded in the test assembly. + /// + protected string GetAssemblyMetadataValue (string key) + { + var assembly = GetType ().Assembly; + var value = assembly + .GetCustomAttributes () + .FirstOrDefault (a => a.Key == key)?.Value; + if (value == null) { + throw new InvalidOperationException ($"AssemblyMetadata '{key}' not found in {assembly.GetName ().Name}"); + } + return value; + } + /// /// Checks if a commercial .NET for Android is available /// * Defaults to Assert.Ignore () diff --git a/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj b/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj index 1d1693df49f..051786dd116 100644 --- a/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj +++ b/tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj @@ -45,6 +45,13 @@ + + + <_Parameter1>MSTestPackageVersion + <_Parameter2>$(MSTestPackageVersion) + + + diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index 6d1d6ea5a8d..fff20607671 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -2248,15 +2248,22 @@ public void DotNetNewAndroidTest (string mode, AndroidRuntime runtime) var dotnet = new DotNetCLI (Path.Combine (projectDirectory, $"{templateName}.csproj")); Assert.IsTrue (dotnet.New ("androidtest"), "`dotnet new androidtest` should succeed"); + // Override the MSTest version from the template with the version used by our build + var msTestVersion = GetAssemblyMetadataValue ("MSTestPackageVersion"); + var csprojPath = Path.Combine (projectDirectory, $"{templateName}.csproj"); + var doc = XDocument.Load (csprojPath); + var ns = doc.Root?.Name.Namespace ?? XNamespace.None; + var msTestRef = doc.Descendants (ns + "PackageReference") + .FirstOrDefault (e => e.Attribute ("Include")?.Value == "MSTest"); + Assert.IsNotNull (msTestRef, "MSTest PackageReference should exist in the generated project"); + msTestRef.SetAttributeValue ("Version", msTestVersion); + doc.Save (csprojPath); + bool useMonoRuntime = runtime == AndroidRuntime.MonoVM; var buildParameters = new List { $"UseMonoRuntime={useMonoRuntime}", }; - if (runtime == AndroidRuntime.CoreCLR) { - Assert.Ignore ("https://github.com/dotnet/android/issues/11174"); - } - // Build and assert 0 warnings Assert.IsTrue (dotnet.Build (parameters: buildParameters.ToArray ()), "`dotnet build` should succeed"); dotnet.AssertHasNoWarnings (); From a891e0de0e913443dde6638ed8943fd2dab09c10 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 24 Apr 2026 11:09:25 -0500 Subject: [PATCH 2/2] [tests] Add test-tools NuGet feed for preview MSTest Pass RestoreAdditionalProjectSources to include the test-tools feed so the preview MSTest package version can be restored during the build. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs index fff20607671..b1380a1bd5b 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs @@ -2262,6 +2262,7 @@ public void DotNetNewAndroidTest (string mode, AndroidRuntime runtime) bool useMonoRuntime = runtime == AndroidRuntime.MonoVM; var buildParameters = new List { $"UseMonoRuntime={useMonoRuntime}", + "RestoreAdditionalProjectSources=https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json", }; // Build and assert 0 warnings