Skip to content

Commit ee90ad9

Browse files
[Xamarin.Android.Build.Tasks] introduce Eol.targets for .NET 6 (#8047)
Fixes: #8003 Add a new `Eol.targets` file to be imported for `net6.0-android` projects. It contains the necessary/minimal settings to emit the build error: Microsoft.NET.EolTargetFrameworks.targets(35,5): error NETSDK1202: The workload 'android' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/maui-support-policy for more information about the support policy. We will probably need the latest .NET SDK to flow to us, in order to write a test. I could only test locally by editing `.targets` files in the .NET SDK.
1 parent dc8f259 commit ee90ad9

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!--
2+
***********************************************************************************************
3+
Eol.targets
4+
5+
Imported only by .NET 6 EOL projects, contains settings to force the error:
6+
7+
error NETSDK1202: The workload 'android' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/maui-support-policy for more information about the support policy.
8+
9+
Things to note:
10+
11+
* $(WarningsAsErrors) includes NETSDK1202
12+
* Force $(TargetPlatformVersion) to just be 21.0, to make it past early error messages
13+
* _ClearMissingWorkloads prevents undesired extra error messages
14+
15+
***********************************************************************************************
16+
-->
17+
<Project InitialTargets="_ClearMissingWorkloads">
18+
<PropertyGroup>
19+
<!-- Force NETSDK1202 to be an error -->
20+
<WarningsAsErrors>$(WarningsAsErrors);NETSDK1202</WarningsAsErrors>
21+
<!--
22+
Along with @(SdkSupportedTargetPlatformVersion), prevents the error:
23+
Microsoft.NET.TargetFrameworkInference.targets(229,5):
24+
error NETSDK1140: 31.0 is not a valid TargetPlatformVersion for android. Valid versions include:
25+
-->
26+
<TargetPlatformSupported>true</TargetPlatformSupported>
27+
<TargetPlatformVersion>21.0</TargetPlatformVersion>
28+
</PropertyGroup>
29+
<ItemGroup>
30+
<SdkSupportedTargetPlatformVersion Include="21.0" />
31+
<EolWorkload Include="android" Url="https://aka.ms/maui-support-policy" />
32+
</ItemGroup>
33+
<Target Name="_ClearMissingWorkloads">
34+
<!--
35+
Prevents the error:
36+
Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147:
37+
To build this project, the following workloads must be installed: wasm-tools-net6
38+
To install these workloads, run the following command: dotnet workload restore
39+
-->
40+
<ItemGroup>
41+
<MissingWorkloadPack Remove="@(MissingWorkloadPack)" />
42+
</ItemGroup>
43+
</Target>
44+
</Project>

src/Xamarin.Android.Build.Tasks/Microsoft.NET.Sdk.Android/WorkloadManifest.in.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '8.0')) " />
55
<Import Project="Sdk.targets" Sdk="Microsoft.Android.Sdk.net7"
66
Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0')) " />
7-
<Import Project="Sdk.targets" Sdk="Microsoft.Android.Sdk.net6"
7+
<Import Project="Eol.targets" Sdk="Microsoft.Android.Sdk.net8"
88
Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) " />
99
</ImportGroup>
1010

@@ -16,7 +16,7 @@
1616
/>
1717
</ItemGroup>
1818

19-
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) ">
19+
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '7.0')) ">
2020
<SdkSupportedTargetPlatformIdentifier Include="android" DisplayName="Android" />
2121
</ItemGroup>
2222
</Project>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,17 @@ public void SettingCombinations (bool isRelease, bool useInterpreter, bool publi
13001300
Assert.AreEqual (expected, builder.Build (), $"{proj.ProjectName} should {(expected ? "succeed" : "fail")}");
13011301
}
13021302

1303+
[Test]
1304+
public void EolFrameworks()
1305+
{
1306+
var library = new XASdkProject (outputType: "Library") {
1307+
TargetFramework = "net6.0-android",
1308+
};
1309+
var dotnet = CreateDotNetBuilder (library);
1310+
Assert.IsFalse (dotnet.Restore (), $"{library.ProjectName} should fail");
1311+
Assert.IsTrue (StringAssertEx.ContainsText (dotnet.LastBuildOutput, "NETSDK1202"), $"{dotnet.BuildLogFile} should have NETSDK1202.");
1312+
}
1313+
13031314
DotNetCLI CreateDotNetBuilder (string relativeProjectDir = null)
13041315
{
13051316
if (string.IsNullOrEmpty (relativeProjectDir)) {

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/DotNetCLI.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ public bool New (string template, string output = null)
9696
return Execute (arguments.ToArray ());
9797
}
9898

99+
public bool Restore (string target = null, string runtimeIdentifier = null, string [] parameters = null)
100+
{
101+
var arguments = GetDefaultCommandLineArgs ("restore", target, runtimeIdentifier, parameters);
102+
return Execute (arguments.ToArray ());
103+
}
104+
99105
public bool Build (string target = null, string runtimeIdentifier = null, string [] parameters = null)
100106
{
101107
var arguments = GetDefaultCommandLineArgs ("build", target, runtimeIdentifier, parameters);

0 commit comments

Comments
 (0)