getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
604 stars 206 forks source link

Fix: NETSDK1139: The target platform identifier android was not recognized #3764

Closed jamescrosswell closed 1 week ago

jamescrosswell commented 1 week ago

Resolve https://github.com/getsentry/sentry-dotnet/issues/3759

Currently investigating.

We don't consistently get this error for the same commit. For example in this build run you can see that in Attempt 1, dotnet restore succeeded. However dotnet restore failed a second attempt on exactly the same commit.

Although both runs use a windows-2022 runner, they are using different image versions:

Successful Run Failed Run
Runner image version 20241021.1.0 20241113.3.0

There is no way to force github to use a specific runner image so it looks like the only solution is to determine what the relevant differences are between these two images and see if we can work around the issue in our build scripts 😢

Potentially relevant image differences

These are some of differences that seem like they might be relevant with respect to the specific error we're encountering:

Successful Run Failed Run
Visual Studio version 17.11.35327.3 17.12.35506.116
android 34.0.113.0 35.0.7.0
Component.Android.SDK.MAUI 17.11.35102.94 17.12.35410.122
maui.core 8.0.82.11329 9.0.0.11787
microsoft.net.runtime.android 8.0.1024.46610 9.0.24.52809
microsoft.net.runtime.android.net7 8.0.1024.46610
microsoft.net.runtime.android.net8 9.0.24.52809
.NET Core SDKs 6.0.135, 6.0.203, 6.0.321, 6.0.427, 7.0.120, 7.0.203, 7.0.317, 7.0.410, 8.0.403 6.0.136, 6.0.203, 6.0.321, 6.0.428, 7.0.120, 7.0.203, 7.0.317, 7.0.410, 8.0.111, 8.0.206, 8.0.307, 8.0.404, 9.0.100

Tracking issue

As this appears to be an issue with the runner rather than our repository, I've opened this issue in the actions/runner repository on github:

skip-changelog

jamescrosswell commented 1 week ago

The specific source of the error is line 117 here:

  <!-- Skip this target for design time builds when there are missing workload packs.
       This will prevent design time builds from failing and therefore allow
       Visual Studio to collect the workloads from the GetSuggestedWorkloads target -->
  <Target Name="_CheckForUnsupportedTargetPlatformIdentifier"
          BeforeTargets="_CheckForInvalidConfigurationAndPlatform;RunResolvePackageDependencies;GetFrameworkPaths;GetReferenceAssemblyPaths;CollectPackageReferences"
          Condition="'$(TargetPlatformIdentifier)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0)) And ('$(DesignTimeBuild)' != 'true' Or '@(MissingWorkloadPack)' == '')" >

    <PropertyGroup>
      <TargetPlatformSupported Condition="'$(TargetPlatformIdentifier)' == 'Windows'">true</TargetPlatformSupported>
      <UseWorkloadsSpecificError Condition="($(TargetPlatformIdentifier) == 'ios' or $(TargetPlatformIdentifier) == 'tvos' or $(TargetPlatformIdentifier) == 'maccatalyst' or $(TargetPlatformIdentifier) == 'android' or $(TargetPlatformIdentifier.StartsWith('browser'))) and '$(MSBuildEnableWorkloadResolver)' != 'true'">true</UseWorkloadsSpecificError>
    </PropertyGroup>

    <NETSdkError Condition="'$(TargetPlatformSupported)' != 'true' and '$(UseWorkloadsSpecificError)' != 'true'"
                 ResourceName="UnsupportedTargetPlatformIdentifier"
                 FormatArguments="$(TargetPlatformIdentifier)" />

    <NETSdkError Condition="'$(TargetPlatformSupported)' != 'true' and '$(UseWorkloadsSpecificError)' == 'true'"
                 ResourceName="UnsupportedTargetPlatformIdentifierWithWorkloadsDisabled"
                 FormatArguments="$(TargetPlatformIdentifier)" />
  </Target>

I'm not really sure I understand this check:

In any event, a diagnostic log of one of our failed runs is attached. Restore Output.zip

Initial errors

It looks like there are some initial errors... some of which appear to be related to the .NET 7 SDK missing (even though we explicitly install this before running dotnet restore).

line 3667

Errors: MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.SDK.WorkloadAutoImportPropsLocator" because directory "C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.NET.SDK.WorkloadAutoImportPropsLocator\Sdk" did not exist.

line 3761

Errors: MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.SDK.WorkloadManifestTargetsLocator" because directory "C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.NET.SDK.WorkloadManifestTargetsLocator\Sdk" did not exist.

line 76,924

Errors: MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.Android.Sdk.net7" because directory "C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.Android.Sdk.net7\Sdk" did not exist.

line 76,938

Errors: MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.Runtime.MonoTargets.Sdk.net7" because directory "C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.NET.Runtime.MonoTargets.Sdk.net7\Sdk" did not exist.

line 323,955

Errors: MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.Maui.Sdk.net7" because directory "C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.Maui.Sdk.net7\Sdk" did not exist.

Apparent Errors

Later eventaully we get the errors that show up in the GitHub console logs... there are 6 of these (for 6 different projects) but they're all more or less the same. Here's one from line 626,480 (the failure happens at the end of this snippet):

22:59:18.904 59:35>Project "D:\a\sentry-dotnet\sentry-dotnet\test\Sentry.Testing\Sentry.Testing.csproj" (59:35) is building "D:\a\sentry-dotnet\sentry-dotnet\test\Sentry.Testing\Sentry.Testing.csproj" (59:47) on node 1 (_GenerateProjectRestoreGraphPerFramework target(s)).
22:59:02.020     1>Project "D:\a\sentry-dotnet\sentry-dotnet\Sentry-CI-Build-Windows.slnf" (1) is building "D:\a\sentry-dotnet\sentry-dotnet\src\Sentry.Serilog\Sentry.Serilog.csproj" (39:18) on node 3 (_GenerateProjectRestoreGraph target(s)).
22:59:19.078 59:47>Target "_GetProjectJsonPath: (TargetId:731)" in file "C:\Program Files\dotnet\sdk\8.0.404\NuGet.targets" from project "D:\a\sentry-dotnet\sentry-dotnet\test\Sentry.Testing\Sentry.Testing.csproj" (target "_GetRestoreProjectStyle" depends on it):
22:59:19.078 59:47>Task "GetRestoreProjectJsonPathTask" skipped, due to false condition; ( '$(RestoreProjectStyle)' == 'ProjectJson' OR '$(RestoreProjectStyle)' == '' ) was evaluated as ( 'PackageReference' == 'ProjectJson' OR 'PackageReference' == '' ).
22:59:19.078 59:47>Done building target "_GetProjectJsonPath" in project "Sentry.Testing.csproj".: (TargetId:731)
                   Target "_CheckForMissingWorkload" skipped, due to false condition; ('@(MissingWorkloadPack)' != '' And '$(DesignTimeBuild)' != 'true') was evaluated as ('' != '' And '' != 'true').
22:59:19.038 27:24>ProcessFrameworkReferences: (TargetId:286)
                     Task Parameter:
                         FrameworkReferences=
                             Microsoft.NETCore.App
                                     IsImplicitlyDefined=true
                                     Pack=false
                                     PrivateAssets=All
                             Microsoft.AspNetCore.App (TaskId:182)
22:59:19.049 41:54>_ComputeToolPackInputsToProcessFrameworkReferences: (TargetId:475)
                   Added Item(s): 
                       _TargetFrameworkToSilenceEnableSingleFileAnalyzerUnsupportedWarning=
                           net6.0
                                   SupportedByMinNonEolTargetFrameworkForAot=True
                                   SupportedByMinNonEolTargetFrameworkForSingleFile=True
                                   SupportedByMinNonEolTargetFrameworkForTrimming=True
                                   SupportsAot=False
                                   SupportsSingleFile=True
                                   SupportsTrimming=True
22:59:19.078 59:47>Target "_CheckForUnsupportedTargetPlatformIdentifier: (TargetId:732)" in file "C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets" from project "D:\a\sentry-dotnet\sentry-dotnet\test\Sentry.Testing\Sentry.Testing.csproj" (target "CollectPackageReferences" depends on it):
22:59:19.078 59:47>Using "NETSdkError" task from assembly "C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.NET.Sdk\targets\..\tools\net8.0\Microsoft.NET.Build.Tasks.dll".
                   Task "NETSdkError" (TaskId:618)
                     Task Parameter:FormatArguments=android (TaskId:618)
                     Task Parameter:ResourceName=UnsupportedTargetPlatformIdentifier (TaskId:618)
22:59:19.038 27:24>ProcessFrameworkReferences: (TargetId:286)
                     Task Parameter:MoreInformationLink=https://aka.ms/sdkimplicitrefs (TaskId:182)
22:59:19.079 59:47>C:\Program Files\dotnet\sdk\8.0.404\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(117,5): error NETSDK1139: The target platform identifier android was not recognized. [D:\a\sentry-dotnet\sentry-dotnet\test\Sentry.Testing\Sentry.Testing.csproj::TargetFramework=net8.0-android]
22:59:19.079 59:47>Done executing task "NETSdkError" -- FAILED. (TaskId:618)
jamescrosswell commented 1 week ago

I suspect but haven't confirmed that this issue actually relates to the net7.0 targets.

We're not seeing this issue on our version-5.0.0 branch where we've already dropped net7.0.

Rather than trying to do root cause analysis on whatever was broken in the latest windows-2022 image runner version then, we've decided to close this issue and expedite the v5.0.0 release.