maui
maui copied to clipboard
[Mac] MAUI Project doesn't build with classlib referenced
Description
On Mac, when trying to build a .NET MAUI project that has a reference to a normal Classlib, the restore and therefore the build process fails with VS 2022 Mac as well as through the command line.
Adding net6.0-maccatalyst to the target frameworks also does not work.
The same project works perfectly on Windows, without having to specify net6-windows as a target framework, as the Mac output would suggest.
Steps to Reproduce
I used the CLI.
- Create a new folder
- Execute
dotnet new sln - Execute
dotnet new maui -n "TestApp" - Execute
dotnet new classlib -n "TestLib" - Either with VS2022 for Mac or manually add the projects to the solution
- Either with VS2022 for Mac or manually add a project reference to reference "TestLib" within "TestApp"
- In VS2022 observe the message "Could not restore packages"
- With the CLI observe the error message when executing
dotnet build -t:Run -f net6.0-maccatalyst
Version with bug
Release Candidate 3 (current)
Last version that worked well
Unknown/Other
Affected platforms
macOS
Affected platform versions
MacOS 12.3.1
Did you find any workaround?
Using a MauiLib in stead of a Classlib works, but this is not the intention of many codebases, I assume.
Relevant log output
/usr/local/share/dotnet/sdk/6.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file '/Users/user/Programming/MauiTest04/TestLib/obj/project.assets.json' doesn't have a target for 'net6.0-maccatalyst'. Ensure that restore has run and that you have included 'net6.0-maccatalyst' in the TargetFrameworks for your project. [/Users/user/Programming/MauiTest04/TestLib/TestLib.csproj]
Would you be able to post a little project that shows this behavior please? It seems a lot like #6717 does any of the info in there help you at all?
Hi @Dokug. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I've seen it work if you build the csproj itself - dotnet build TestApp/TestApp.csproj -f net6.0-maccatalyst.
Building from the solution does not - dotnet build -f net6.0-maccatalyst
Oh yes that's interesting, thank you @duraz0rz!
@Dokug would you be able to confirm if you point to the csproj if it works then? I think somewhere in the linked issue we also mentioned that the sln isn't supported for reasons
Hi @Dokug. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@jfversluis Yes, performing dotnet build on the MAUI-csproj works, however the app then displays none of the UI. See picture 1 (Windows) vs picture 2 (Mac).
I'll create and post a sample project once I get the chance later in the evening.

I think somewhere in the linked issue we also mentioned that the sln isn't supported for reasons
@jfversluis Is running dotnet CLI commands on the solution generally unsupported for single project MAUI applications? Does it make sense for the dotnet new maui template to create a sln file if it's unsupported?
I admit I am confused now: I tried putting together a sample project to upload but the following happened:
- Initially, building with VS2022 did not work, after adding the project reference
- Building the csproj through the CLI worked, and it correctly showed the UI
- Then, building with VS2022 suddenly worked, after changing a little code, to more closely match my original project
Curiously enough, I can't recreate the effect of building with the CLI and the UI disappearing on the new project, but my own project (which was created with dotnet new maui with RC1) still has the same issue.
I will continue investigating and come back to you once I figure this out.
@Dokug Try doing a dotnet clean after you build from the CLI and see if it still works in VS2022.
After a clean re-install of .NET 6.0.300 and MAUI it now works when performing dotnet clean and then dotnet build -t:Run -f net6.0-maccatalyst on the MAUI csproj.
I think this was an issue with previous .NET or MAUI versions messing with the system.
repro with vs main build(32626.21). as duraz0rz and Dokug said, we can build the project but failed to build the solution.
This is still an issue.
@janduldhardt can you elaborate on what the issue is. According to @Dokug, the issue appears to be fixed.
Maybe open a new issue and fill in all the boxes with versions, platform, repos and more as it may be a different issue. Or maybe add more info here if you feel it is the same issue.
No response, if this is still an issue for someone, please open a new issue with the requested information. Thank you!