Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build with VS4Mac: nuget issue #1641

Closed
janusw opened this issue Jun 13, 2022 · 20 comments
Closed

Cannot build with VS4Mac: nuget issue #1641

janusw opened this issue Jun 13, 2022 · 20 comments

Comments

@janusw
Copy link
Member

janusw commented Jun 13, 2022

Describe the bug

I am currently unable to build Mapsui on MacOS (via Mapui.Mac.sln), because I get the following error when restoring packages:

/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018: The "WriteRestoreGraphTask" task failed unexpectedly. [/Users/janus/github/Mapsui/Mapsui.Mac.sln]

/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018: NuGet.Frameworks.FrameworkException: Invalid framework identifier ''. [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.Frameworks.NuGetFramework.GetShortFolderName (NuGet.Frameworks.IFrameworkNameProvider mappings) [0x0006f] in <2a53adb0a2a749ef96359f00e82d80ae>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.Frameworks.NuGetFramework.GetShortFolderName () [0x00006] in <2a53adb0a2a749ef96359f00e82d80ae>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.ProjectModel.PackageSpecWriter.WriteMetadataTargetFrameworks (NuGet.RuntimeModel.IObjectWriter wri
ter, NuGet.ProjectModel.ProjectRestoreMetadata msbuildMetadata) [0x00074] in <fa433204210e44b19f17d9e99703474c>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.ProjectModel.PackageSpecWriter.SetMSBuildMetadata (NuGet.RuntimeModel.IObjectWriter writer, NuGet.ProjectModel.PackageSpec packageSpec) [0x00119] in <fa433204210e44b19f17d9e99703474c>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.ProjectModel.PackageSpecWriter.Write (NuGet.ProjectModel.PackageSpec packageSpec, NuGet.RuntimeModel.IObjectWriter writer, System.Boolean compressed) [0x000bf] in <fa433204210e44b19f17d9e99703474c>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.ProjectModel.Depende
ncyGraphSpec.Write (NuGet.RuntimeModel.IObjectWriter writer, System.Boolean compressed, System.Action`3[T1,T2,T3] writeAction) [0x0009b] in <fa433204210e44b19f17d9e99703474c>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.ProjectModel.DependencyGraphSpec.Save (System.String path) [0x00024] in <fa433204210e44b19f17d9e99703474c>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at NuGet.Build.Tasks.WriteRestoreGraphTask.Execute () [0x000e8] in <25234f4e8adb47da8ff1bbd8fbc3507b>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <6f1ac64b362443459ae7e79676b4c67f>:0
  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]
/Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/NuGet.targets(162,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002b9] in <6f1ac64b362443459ae7e79676b4c67f>:0  [/Users/janus/github/Mapsui/Mapsui.Mac.sln]

To Reproduce

... simply open Mapsui.Mac.sln in VS4Mac.

I'm using Visual Studio for Mac 2022 version 17.0.2 on MacOS Monterey (12.4) on a MacBook Pro with M1 chip (Apple silicon).

Does anyone have the same problem, or is it just me?

I already tried reinstalling VS4Mac and cleaning the Mapsui directory, but nothing helped so far.

@janusw
Copy link
Member Author

janusw commented Jun 13, 2022

Btw, running nuget restore Mapsui.Mac.sln in a terminal fails with the same error, while dotnet restore Mapsui.Mac.sln works fine (SDK Version 6.0.300).

Running nuget in the terminal tells me it is version 5.9.0.7134 (installed in /Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget, so coming from Mono), but VS4Mac says it includes nuget v6.0.0.262.

The GitHub Actions Mac build works fine (it's using dotnet restore).

@janusw
Copy link
Member Author

janusw commented Jun 13, 2022

The GitHub Actions Mac build works fine (it's using dotnet restore).

This was changed from nuget restore by @pauldendulk in bbe99a9 (as part of #1588), probably because nuget restore did not work any more with the new .NET 6 projects?

In fact the error message from above is visible here: https://github.com/Mapsui/Mapsui/runs/6027476550
(This is the commit before dotnet restore was introduced.)

@janusw
Copy link
Member Author

janusw commented Jun 13, 2022

Btw, running nuget restore Mapsui.Mac.sln in a terminal fails with the same error, while dotnet restore Mapsui.Mac.sln works fine (SDK Version 6.0.300).

Running nuget in the terminal tells me it is version 5.9.0.7134 (installed in /Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget, so coming from Mono), but VS4Mac says it includes nuget v6.0.0.262.

nuget 5.9 is obviously too old and not fit for restoring .NET 6 projects (https://docs.microsoft.com/en-us/nuget/release-notes/nuget-6.0). Question is why VS4Mac uses that old version from Mono, instead of the new 6.x it ships with. Strongly smells like a VS bug.

@inforithmics
Copy link
Contributor

inforithmics commented Jun 13, 2022

Old xamarin projects are run with the old Mono Tooling. whereas . Net 6 is built by the new dotnet Tooling. A workaround is to run on the command line dotnet commands so it uses the new Tooling.

probably this issue
mono/mono#21502

Unfortunatly this is only on the Mac the case on Windows it works.

@inforithmics
Copy link
Contributor

inforithmics commented Jun 13, 2022

I had more success with Rider as the IDE of choice on the Mac. I think Visual Studio for Mac Preview has some fixes too because it supports Maui so you could try that if it builds

@janusw
Copy link
Member Author

janusw commented Jun 14, 2022

Old xamarin projects are run with the old Mono Tooling. whereas . Net 6 is built by the new dotnet Tooling. A workaround is to run on the command line dotnet commands so it uses the new Tooling.

probably this issue mono/mono#21502

Well, updating nuget in Mono would probably help with my problem, but I think the real issue is more with VS than with Mono. In a 'mixed' solution (.NET 6 + classical Xamarin), VS should better use the new tooling instead of the old one, shouldn't it? I guess I will raise a VS ticket for this.

Unfortunatly this is only on the Mac the case on Windows it works.

You mean "fortunately" here, right? 🤣

Seriously though, it's a shame that, although MS has been developing "cross-platform" frameworks (.NET Core, Xamarin and MAUI) for years now, the development environment is still completely Windows-centered, with Mac and Linux being second-class citizens that no one at MS seems to care about. (Sorry for the rant, but it is kind of frustrating at times.)

@inforithmics
Copy link
Contributor

I think they introduced this problem here

https://developercommunity.visualstudio.com/t/Package-restore-fails-in-VS-for-Mac-170/1677883

Before solutions with more than 10 projects where build with the dotnet msbuild, afterwards projects that contain classic Xamarin Forms are built with msbuild from Mono which is ancient.

The workaround described there is dotnet restore on command line and disable automatic nuget restore in IDE.

@janusw
Copy link
Member Author

janusw commented Jun 14, 2022

I had more success with Rider as the IDE of choice on the Mac. I think Visual Studio for Mac Preview has some fixes too because it supports Maui so you could try that if it builds

Tried VS4Mac 2022 Preview (version 17.3 build 198). Same problem.

I guess I might indeed move to Rider if the pain with VS persists.

@janusw
Copy link
Member Author

janusw commented Jun 14, 2022

The workaround described there is dotnet restore on command line and disable automatic nuget restore in IDE.

Yes, that workaround gets me past the error above, but then I actually get another one when trying to build the Mapsui base project:

error MSB4236: The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified could not be found.

This is dotnet/sdk#17461, there is a workaround as well, which will probably take me to the next bug (haven't actually tried yet). 🙈

I have to conclude that, as of today, MS's tooling for .NET 6 is simply not ready for prime time, at least not on Mac.

@pauldendulk
Copy link
Member

I think most of our problems arise from the 'mixed' solutions. I have just a couple of hours a week to work on Mapsui an often they all go to waste because of weird build problems. I would like to drop all older platforms in Mapsui v5 and only support .NET 6 (or 7 by then).

@inforithmics
Copy link
Contributor

inforithmics commented Jun 15, 2022

I opened an Feedback issue for Visual Studio for Mac here:
MSB4236 The SDK Microsoft.Net... was not found

Because in other IDEs it works so its clearly a Visual Studio for Mac issue:

@inforithmics
Copy link
Contributor

According to the discussion in the Visual Studio for Mac Issue. Visual Studio for Mac does not like mixed Solutions (Mono/NET6) So I think I could split Mapsui.Mac.sln into two solutions.
Mapsui.Mac.Legacy.sln (with only Xamarin.Forms (with disabling of the NET6 targets)
Mapsui.Mac.sln (for NET6 Targets (maybe adding Maui, Uno, Avalonia, Eto ))

@pauldendulk
Copy link
Member

I am not opposed to this but I am not developing on Mac.

btw, I see that the Microsoft projects often use a .slnf file. This is a filter on sln. Perhaps we should also use these more often. Not sure if that would help here. https://docs.microsoft.com/en-us/visualstudio/msbuild/solution-filters?view=vs-2022

@inforithmics
Copy link
Contributor

Here I made a pull request

@janusw can you have a look at it.
You have to use Mapsui.Mac.Legacy.sln
and set following on the commandline

launchctl setenv MSBuildEnableWorkloadResolver false

#1644

@inforithmics
Copy link
Contributor

Regarding the .slnf I have to test it if the workaround for mapsui.mac.legacy.sln works for mapsui.mac.legacy.slnf too.

@inforithmics
Copy link
Contributor

No it won't work because I don't have access to the SolutionFilterName.
see:
dotnet/msbuild#6162

@inforithmics
Copy link
Contributor

But I think I could make a Mapsui.Mac.slnf (That removes the Windows Projects for the Mac) and the Mapsui.Mac.Legacy could be renamed to Mapsui.Mac.sln

@inforithmics
Copy link
Contributor

If done this now in the pull request

@inforithmics
Copy link
Contributor

For clarity I renamed it back

@janusw
Copy link
Member Author

janusw commented Jun 24, 2022

This issue is fixed (or at least worked around) by #1644.

@janusw janusw closed this as completed Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants