|
1 | 1 | using System.Diagnostics; |
2 | 2 | using System.Runtime.InteropServices; |
| 3 | +using System.Text.RegularExpressions; |
3 | 4 | using Microsoft.Maui.IntegrationTests.Android; |
4 | 5 |
|
5 | 6 | namespace Microsoft.Maui.IntegrationTests |
@@ -94,6 +95,12 @@ public void RunOnAndroid(string id, string framework, string config, string? tri |
94 | 95 | Assert.True(DotnetInternal.New(id, projectDir, framework, output: _output), |
95 | 96 | $"Unable to create template {id}. Check test output for errors."); |
96 | 97 |
|
| 98 | + // On Linux, only the maui-android workload is installed. Previous .NET |
| 99 | + // templates may still include iOS/macOS TFMs causing NETSDK1178 errors |
| 100 | + // during restore. Strip them so only Android remains. |
| 101 | + if (TestEnvironment.IsLinux) |
| 102 | + StripNonAndroidTfms(projectFile, framework); |
| 103 | + |
97 | 104 | var buildProps = BuildProps; |
98 | 105 | if (!string.IsNullOrEmpty(trimMode)) |
99 | 106 | { |
@@ -128,5 +135,20 @@ void AddInstrumentation(string projectDir) |
128 | 135 | "MainLauncher = true, Name = \"com.microsoft.mauitemplate.MainActivity\""); |
129 | 136 | } |
130 | 137 |
|
| 138 | + static void StripNonAndroidTfms(string projectFile, string framework) |
| 139 | + { |
| 140 | + var content = File.ReadAllText(projectFile); |
| 141 | + var androidTfm = $"{framework}-android"; |
| 142 | + // Remove conditional TargetFrameworks lines (iOS/macOS/Windows additions) |
| 143 | + content = Regex.Replace(content, |
| 144 | + @"\s*<TargetFrameworks\s+Condition=""[^""]*"">[^<]*</TargetFrameworks>", |
| 145 | + ""); |
| 146 | + // Set the base TargetFrameworks to Android only |
| 147 | + content = Regex.Replace(content, |
| 148 | + @"<TargetFrameworks>[^<]*</TargetFrameworks>", |
| 149 | + $"<TargetFrameworks>{androidTfm}</TargetFrameworks>"); |
| 150 | + File.WriteAllText(projectFile, content); |
| 151 | + } |
| 152 | + |
131 | 153 | } |
132 | 154 | } |
0 commit comments