maui icon indicating copy to clipboard operation
maui copied to clipboard

[Mac] MAUI Project doesn't build with classlib referenced

Open Dokug opened this issue 3 years ago • 13 comments

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.

  1. Create a new folder
  2. Execute dotnet new sln
  3. Execute dotnet new maui -n "TestApp"
  4. Execute dotnet new classlib -n "TestLib"
  5. Either with VS2022 for Mac or manually add the projects to the solution
  6. Either with VS2022 for Mac or manually add a project reference to reference "TestLib" within "TestApp"
  7. In VS2022 observe the message "Could not restore packages"
  8. 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]

Dokug avatar May 13 '22 14:05 Dokug

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?

jfversluis avatar May 13 '22 14:05 jfversluis

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.

ghost avatar May 13 '22 14:05 ghost

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

duraz0rz avatar May 13 '22 14:05 duraz0rz

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

jfversluis avatar May 13 '22 14:05 jfversluis

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.

ghost avatar May 13 '22 14:05 ghost

@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.

image image

Dokug avatar May 13 '22 15:05 Dokug

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?

duraz0rz avatar May 13 '22 17:05 duraz0rz

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 avatar May 13 '22 23:05 Dokug

@Dokug Try doing a dotnet clean after you build from the CLI and see if it still works in VS2022.

duraz0rz avatar May 14 '22 15:05 duraz0rz

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.

Dokug avatar May 15 '22 15:05 Dokug

repro with vs main build(32626.21). as duraz0rz and Dokug said, we can build the project but failed to build the solution.

VincentBu avatar Jun 27 '22 05:06 VincentBu

This is still an issue.

janduldhardt avatar Oct 19 '22 11:10 janduldhardt

@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.

mattleibow avatar Nov 10 '22 20:11 mattleibow

No response, if this is still an issue for someone, please open a new issue with the requested information. Thank you!

jfversluis avatar Mar 14 '23 12:03 jfversluis