maui: Publish MAUI Project with project reference To Class library produces errors.
Description
Publish MAUI Project with project reference To Class library produces errors.
Steps to Reproduce
- Create Maui Project.
- Add Class library A.
- Add Class library B.
- Add project reference from MAUI projects for two class librariles.
- Publish according to this documents: https://docs.microsoft.com/en-us/dotnet/maui/windows/deployment/overview
- I used this commands:
New-SelfSignedCertificate -Type Custom -Subject "CN=Dani" -KeyUsage DigitalSignature -FriendlyName "My temp dev cert" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")
Get-ChildItem "Cert:\CurrentUser\My" | Format-Table Subject, FriendlyName, Thumbprint
msbuild /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=true /p:PackageCertificateThumbprint="44CF7D6F1FD0B7CF538085CBEA22A1B0ACDBB541"
- Get error in build phase, please see Relevant log output
Version with bug
Release Candidate 1
Last version that worked well
Release Candidate 1
Affected platforms
Windows
Affected platform versions
…
Did you find any workaround?
No
Relevant log output
"C:\Users\danis\Desktop\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj" (Restore target) (1) ->
(Restore target) ->
C:\Users\danis\Desktop\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-android31.0 (.NETCoreApp,Version=v6.0). Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-ios15.4 (.NETCoreApp,Version=v6.0). Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-maccatalyst15.4 (.NETCoreApp,Version=v6.0). Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-android31.0 (.NETCoreApp,Version=v6.0) / win10-x64. Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-ios15.4 (.NETCoreApp,Version=v6.0) / win10-x64. Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-maccatalyst15.4 (.NETCoreApp,Version=v6.0) / win10-x64. Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
0 Warning(s)
6 Error(s)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (11 by maintainers)
@mattleibow Thanks for the explanation! Now I can ditch my hefty workaround of going via nuget packages for my 10ish .NET 6 class libraries 😃
OK, so some interesting news and this feels like either a bug or a limitation of msbuild.
If you switch to dotnet build you get an error about TFMs, but this is easily fixed by adding a .0 to the end of the windows TFM:
However, for msbuild, it appears the single command of
msbuild /restorethrows off the part with the TFM. If you do it in 2 steps then it works:I think the fact that you specify a TFM during the restore somehow throws of the restore process. This can be repro-ed with just the restore target:
There is another workaround for this and it is probably due to the fact that the CLI arguments OVERWRITE the properties in the csproj. The workaround is to just change the singular
<TargetFramework>in the class library to the plural version<TargetFrameworks>.As a result, the CLI argument of
/p:TargetFramework=net6.0-windows10.0.19041.0no longer OVERWRITES the property but instructs the build to SELECT the best matching TFM.Thanks! Looking now and will try find the issue and reopen if it is a bug or reply here with anything that is dodgy.
Duplicate of #6831
I was able to repro the error with the CLI of:
But all is well with the extra .0:
I also get another error when I try publish the solution and that is unsupported. If you publish with the solution, you instruct the tooling to publish each project in the solution - so effectively you instruct the CLI to publish a net6.0 class library as a windows app - which is probably not what you are wanting.
The correct way to publish is using the project file - using a TFM that matches the one in the csproj as it is basically a selector of the items in there.
This may be because you are publishing a
net6.0-windows10.0.19041TFM, but the app TFM is the one with an extra.0suffix:net6.0-windows10.0.19041.0