dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

Building legacy iOS projects fails with latest Mono and .NET 6.0.300 SDK #25651

Open rolfbjarne opened 2 years ago

rolfbjarne commented 2 years ago

From @filipnavara on Wed, 25 May 2022 18:14:45 GMT

Steps to Reproduce

  1. Get a .NET 6.0.300 SDK installed on a clean macOS machine along with legacy Mono SDKs (installed through VS4Mac for example)
  2. Try to build legacy Xamarin.iOS app with ProjectReference to a netstandard2.1;net6.0-macos project.

Expected Behavior

Build succeeds.

Actual Behavior

"/Users/filipnavara/Projects/emclient-temp/MailClient.Mobile/MailClient.Mobile.iOS/MailClient.Mobile.iOS.csproj" (Restore target) (1) ->
(Restore target) -> 
  /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/NuGet.targets(131,5): error : Invalid framework identifier ''. [/Users/filipnavara/Projects/emclient-temp/MailClient.Mobile/MailClient.Mobile.iOS/MailClient.Mobile.iOS.csproj]

Environment

Mono 6.12.0.174 (particular version didn't seem to matter) .NET SDK 6.0.300

NOTE: It works if any older SDK band, such as 6.0.203, is installed on the machine. It works even when both 6.0.203 and 6.0.300 are present. The failure happens only when 6.0.300 is the only SDK band installed.

Build Logs

msbuild.binlog.zip

Copied from original issue xamarin/xamarin-macios#15124

rolfbjarne commented 2 years ago

From @filipnavara on Wed, 25 May 2022 18:20:27 GMT

I'm still trying to reduce it to simple failing project, will post it here if I succeed.

rolfbjarne commented 2 years ago

From @filipnavara on Wed, 25 May 2022 18:28:29 GMT

Exception seem in binlog:

NuGet.Frameworks.FrameworkException: Invalid framework identifier ''.
  at NuGet.Frameworks.NuGetFramework.GetShortFolderName (NuGet.Frameworks.IFrameworkNameProvider mappings) [0x0006f] in <6c0a2d3846b042c794c1e783f026c718>:0 
  at NuGet.Frameworks.NuGetFramework.GetShortFolderName () [0x00006] in <6c0a2d3846b042c794c1e783f026c718>:0 
  at NuGet.ProjectModel.PackageSpecWriter.WriteMetadataTargetFrameworks (NuGet.RuntimeModel.IObjectWriter writer, NuGet.ProjectModel.ProjectRestoreMetadata msbuildMetadata) [0x00074] in <17538cbeb464462399c05c20f9a6d744>:0 
  at NuGet.ProjectModel.PackageSpecWriter.SetMSBuildMetadata (NuGet.RuntimeModel.IObjectWriter writer, NuGet.ProjectModel.PackageSpec packageSpec) [0x00119] in <17538cbeb464462399c05c20f9a6d744>:0 
  at NuGet.ProjectModel.PackageSpecWriter.Write (NuGet.ProjectModel.PackageSpec packageSpec, NuGet.RuntimeModel.IObjectWriter writer, System.Boolean compressed) [0x000bf] in <17538cbeb464462399c05c20f9a6d744>:0 
  at NuGet.ProjectModel.DependencyGraphSpec.Write (NuGet.RuntimeModel.IObjectWriter writer, System.Boolean compressed, System.Action`3[T1,T2,T3] writeAction) [0x0009b] in <17538cbeb464462399c05c20f9a6d744>:0 
  at NuGet.ProjectModel.DependencyGraphSpec.GetHash () [0x0000d] in <17538cbeb464462399c05c20f9a6d744>:0 
  at NuGet.Commands.RestoreCommand.EvaluateCacheFile () [0x00033] in <dc66751e866e46138a8178ce3f6e98f2>:0 
  at NuGet.Commands.RestoreCommand.ExecuteAsync (System.Threading.CancellationToken token) [0x0015e] in <dc66751e866e46138a8178ce3f6e98f2>:0 
  at NuGet.Commands.RestoreRunner.ExecuteAsync (NuGet.Commands.RestoreSummaryRequest summaryRequest, System.Threading.CancellationToken token) [0x0009f] in <dc66751e866e46138a8178ce3f6e98f2>:0 
  at NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync (NuGet.Commands.RestoreSummaryRequest summaryRequest, System.Threading.CancellationToken token) [0x00070] in <dc66751e866e46138a8178ce3f6e98f2>:0 
  at NuGet.Commands.RestoreRunner.CompleteTaskAsync (System.Collections.Generic.List`1[T] restoreTasks) [0x000ce] in <dc66751e866e46138a8178ce3f6e98f2>:0 
  at NuGet.Commands.RestoreRunner.RunAsync (System.Collections.Generic.IEnumerable`1[T] restoreRequests, NuGet.Commands.RestoreArgs restoreContext, System.Threading.CancellationToken token) [0x0014b] in <dc66751e866e46138a8178ce3f6e98f2>:0 
  at NuGet.Commands.RestoreRunner.RunAsync (NuGet.Commands.RestoreArgs restoreContext, System.Threading.CancellationToken token) [0x000cd] in <dc66751e866e46138a8178ce3f6e98f2>:0 
  at NuGet.Build.Tasks.BuildTasksUtility.RestoreAsync (NuGet.ProjectModel.DependencyGraphSpec dependencyGraphSpec, System.Boolean interactive, System.Boolean recursive, System.Boolean noCache, System.Boolean ignoreFailedSources, System.Boolean disableParallel, System.Boolean force, System.Boolean forceEvaluate, System.Boolean hideWarningsAndErrors, System.Boolean restorePC, System.Boolean cleanupAssetsForUnsupportedProjects, NuGet.Common.ILogger log, System.Threading.CancellationToken cancellationToken) [0x0036a] in <284aae14d5034455899563954b017376>:0 
  at NuGet.Build.Tasks.RestoreTask.ExecuteAsync (NuGet.Common.ILogger log) [0x000f1] in <284aae14d5034455899563954b017376>:0 
rolfbjarne commented 2 years ago

From @filipnavara on Wed, 25 May 2022 18:48:05 GMT

Sample project: Archive.zip Build step: msbuild FooApp/FooApp.csproj /restore

The trigger seems to be <TargetFrameworks>netstandard2.1;net6.0-macos</TargetFrameworks> in the referenced library project.

With 6.0.300 SDK I get the error above. With 6.0.203 SDK I get:

"/Users/filipnavara/Projects/FooApp/FooApp/FooApp.csproj" (Restore target) (1) ->
"/Users/filipnavara/Projects/FooApp/FooLib/FooLib.csproj" (_GenerateProjectRestoreGraph target) (2:8) ->
"/Users/filipnavara/Projects/FooApp/FooLib/FooLib.csproj" (_GenerateProjectRestoreGraphPerFramework target) (2:12) ->
(_CheckForMissingWorkload target) -> 
  /usr/local/share/dotnet/sdk/6.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To build this project, the following workloads must be installed: macos [/Users/filipnavara/Projects/FooApp/FooLib/FooLib.csproj]
/usr/local/share/dotnet/sdk/6.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.targets(38,5): error NETSDK1147: To install these workloads, run the following command: dotnet workload install macos [/Users/filipnavara/Projects/FooApp/FooLib/FooLib.csproj]

With the macOS workload installed [on the 6.0.203 SDK] the build succeeds.

rolfbjarne commented 2 years ago

From @filipnavara on Wed, 25 May 2022 18:50:44 GMT

cc @dsplaisted ... seems more like SDK and/or NuGet bug, to be honest. Did something change significantly for the 6.0.300 band? (Mono ships MSBuild 16.10.1.17201)

rolfbjarne commented 2 years ago

From @rolfbjarne on Thu, 26 May 2022 07:39:09 GMT

I agree, this doesn't look like a bug in xamarin-macios.

I'm not sure where it should be moved to though, maybe dotnet/sdk?

rolfbjarne commented 2 years ago

From @filipnavara on Thu, 26 May 2022 07:58:05 GMT

I'm not sure where it should be moved to though, maybe dotnet/sdk?

That's the difficult part. It could either be mono/mono because of the unusual interaction of the packaged old version of MSBuild, or dotnet/sdk. I'm leaning towards dotnet/sdk since part of the problem is the workload logic not triggering properly and resulting in unknown TFMs. The other part is the totally useless error message.

marcpopMSFT commented 2 years ago

@steveisok @lewing to take a look.

lewing commented 2 years ago

given that is works on earlier 6.0.xxx sdks I'm not sure what is going on but https://github.com/dotnet/runtime/pull/72147 is worth landing for many reasons

mstefarov commented 2 years ago

Still seeing this error (or something very similar) with .NET 7 RC1. Running dotnet restore on a solution that targets netstandard2.0;net6.0;net6.0-ios14.0;net6.0-android31.0;net6.0-maccatalyst14.2, on MacOS:

/usr/local/share/dotnet/sdk/7.0.100-rc.1.22431.12/NuGet.targets(132,5): Invalid framework identifier ''.
NuGet.Frameworks.FrameworkException: Invalid framework identifier ''.
   at NuGet.Frameworks.NuGetFramework.GetShortFolderName(IFrameworkNameProvider mappings)
   at NuGet.Frameworks.NuGetFramework.GetShortFolderName()
   at NuGet.Commands.MSBuildRestoreUtility.<>c__DisplayClass6_0.<GetPackageSpec>b__0(TargetFrameworkInformation tfi)
   at NuGet.Shared.Extensions.ForEach[T](IEnumerable`1 enumeration, Action`1 action)
   at NuGet.Commands.MSBuildRestoreUtility.GetPackageSpec(IEnumerable`1 items)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at NuGet.Commands.MSBuildRestoreUtility.GetDependencySpec(IEnumerable`1 items)
   at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)
marcpopMSFT commented 2 years ago

@lewing to take a look.

steveisok commented 2 years ago

@akoeplinger can you see what might be the problem?

akoeplinger commented 2 years ago

@mstefarov do you have any legacy Xamarin/.NET4 projects in your solution? It shouldn't happen with a pure .NET 6 based project.

I can reproduce Filip's original issue but no idea why it happens.

marcpopMSFT commented 2 years ago

I'm not sure workloads supports mono and I don't think the fork of msbuild for mono has been building for over a year now. It's possible it was made to work back when 6.0.1xx came out as VSMac was still on mono then but mono support may be the limitation here.

marcpopMSFT commented 2 years ago

@lewing and @steveisok to reply as we think mono support may have just worked by luck.

jingliancui commented 1 year ago

This error will occur when I use cake script to invoke MSBuild() to build iOS binding project in mac as well.

Microsoft (R) Build Engine version 16.10.1 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 11/4/2022 4:41:07 PM.
     1>Project "/Users/ericcui/Desktop/GitHubWorkspace/XamarinIOSBindingLibrary/TencentOpenAPI/3.5.12/TencentOpenAPIBinding/TencentOpenAPIBinding.sln" on node 1 (Restore target(s)).
     1>ValidateSolutionConfiguration:
         Building solution configuration "Release|Any CPU".
       _GetAllRestoreProjectPathItems:
         Determining projects to restore...
     1>/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/NuGet.targets(131,5): error : Invalid framework identifier ''. [/Users/ericcui/Desktop/GitHubWorkspace/XamarinIOSBindingLibrary/TencentOpenAPI/3.5.12/TencentOpenAPIBinding/TencentOpenAPIBinding.sln]
     1>Done Building Project "/Users/ericcui/Desktop/GitHubWorkspace/XamarinIOSBindingLibrary/TencentOpenAPI/3.5.12/TencentOpenAPIBinding/TencentOpenAPIBinding.sln" (Restore target(s)) -- FAILED.

Build FAILED.

       "/Users/ericcui/Desktop/GitHubWorkspace/XamarinIOSBindingLibrary/TencentOpenAPI/3.5.12/TencentOpenAPIBinding/TencentOpenAPIBinding.sln" (Restore target) (1) ->
       (Restore target) -> 
         /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/NuGet.targets(131,5): error : Invalid framework identifier ''. [/Users/ericcui/Desktop/GitHubWorkspace/XamarinIOSBindingLibrary/TencentOpenAPI/3.5.12/TencentOpenAPIBinding/TencentOpenAPIBinding.sln]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.90
An error occurred when executing task 'Build'.
Error: MSBuild: Process returned an error (exit code 1).