Closed danies8 closed 2 years ago
@mattleibow is this a matter of setting some msbuild properties?
@jfversluis maybe you have some input here too?
Looks like a duplicate of #5833
Reproduce also in VS Version 17.2.0 Preview 5.0,
When I add this to csproj of class library:
<TargetFramework Condition="'$(BuildWindowsOnly)' == 'true'">net6.0-windows10.0.19041</TargetFramework>
and comment
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
on MAU project csproj file.
and-p:BuildWindowsOnly=true
to build command it work.
But you have to fix it :))
FYI, with earlier previews, I was able to work around this issue by creating nuget packages for the .NET 6 assemblies and letting the MAUI project refer to those packages rather than using project references.
With VS Community 2022 - preview version 17.2.0 Preview 6.0, the issue is still present and the nuget workaround seems to work, although I get the below error
C:\Program Files\dotnet\sdk\6.0.300-preview.22204.3\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5):
error NETSDK1005: Assets file 'C:\...\obj\project.assets.json' doesn't have a target for 'net6.0-windows10.0.19041'.
Ensure that restore has run and that you have included 'net6.0-windows10.0.19041' in the TargetFrameworks for your project.
which is reported as a separate issue here: https://github.com/dotnet/maui/issues/6831
This may be because you are publishing a net6.0-windows10.0.19041
TFM, but the app TFM is the one with an extra .0
suffix: net6.0-windows10.0.19041.0
Duplicate of #6831
I was able to repro the error with the CLI of:
dotnet publish -f net6.0-windows10.0.19041 -c Release
But all is well with the extra .0:
dotnet publish -f net6.0-windows10.0.19041.0 -c Release
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.
Added a note about the sln publishing to the docs: https://github.com/dotnet/docs-maui/pull/508 as well as the TFM that need to match up
@mattleibow a quick test on my devbox shows that the present issue (#6717) with project references to .NET 6 class libraries still exist in MAUI RC2 / VS 2022 17.2 Preview 6 - did you mean to close this issue?
@Dbquity can you attach a binlog? Maybe our projects don't quite match... or a repro case so I can test.
@mattleibow Quick reply is the repro I created earlier at https://github.com/Dbquity/MauiApp1 Its .csproj files are of cause out-of-date by bow, but the issue reproes by a dependency chain similar to this (which is what I have in my Dbquity solution): MauiApp --> MauiLib --> .NET6Lib The present issue suggests that even MauiApp --> .NET6Lib fails.
@Dbquity can you attach a binlog? Maybe our projects don't quite match... or a repro case so I can test.
@mattleibow created a simple repro here: https://github.com/Dbquity/Repro6717
Thanks! Looking now and will try find the issue and reopen if it is a bug or reply here with anything that is dodgy.
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:
dotnet build MauiApp1 /p:TargetFramework=net6.0-windows10.0.19041
However, for msbuild, it appears the single command of msbuild /restore
throws off the part with the TFM. If you do it in 2 steps then it works:
msbuild /t:restore MauiApp1
msbuild MauiApp1 /p:TargetFramework=net6.0-windows10.0.19041.0
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:
msbuild /t:restore MauiApp1 /p:TargetFramework=net6.0-windows10.0.19041.0
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.0
no longer OVERWRITES the property but instructs the build to SELECT the best matching TFM.
@mattleibow Thanks for the explanation! Now I can ditch my hefty workaround of going via nuget packages for my 10ish .NET 6 class libraries :-)
@davidbritch @jfversluis Maybe @mattleibow 's point about splitting out the restore step when you have dependencies on .NET 6 class libraries warrants a mention in the documentation at https://github.com/dotnet/docs-maui/issues/352
We'll be looking forward to you PR @Dbquity 😝
@jfversluis that smells like work - I'll PO (pull out) instead ;-)
@jfversluis
Jokes aside, since the subtlety of handling .NET 6 class library project references only pertains to msbuild
and MAUI is using dotnet publish
, I guess a PR on the docs would be less relevant.
If you think otherwise, let me know, and I'll be happy to do my first github PR as an exercise :-)
So the publish will be like this document ? ( Publish the MAUI project using this link: https://docs.microsoft.com/en-us/dotnet/maui/windows/deployment/overview )
That is correct.
Great:) in which version I can see this fix ?
@danies8 fix? The fix is to either use dotnet build or to use 2 separate restore and then publish commands. Unless I am misreading your question?
https://github.com/dotnet/maui/issues/6717#issuecomment-1118415277
dotnet build /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041.0 /p:configuration=release /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=true /p:PackageCertificateThumbprint="5F1A782863655040EC3AE2E0C2132A1A04AC6618
"C:\Users\danis\Desktop\11_05_2022_unc client check\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-android31.0 (.NET
CoreApp,Version=v6.0). Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\11_05_2022_unc client check\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-ios15.4 (.NETCore
App,Version=v6.0). Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\11_05_2022_unc client check\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\11_05_2022_unc client check\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-android31.0 (.NET
CoreApp,Version=v6.0) / win10-x64. Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\11_05_2022_unc client check\AutomationClient\AutomationClient.MAUI\AutomationClient.MAUI.csproj : error NU1201: Project AutomationClient.Shared is not compatible with net6.0-ios15.4 (.NETCore
App,Version=v6.0) / win10-x64. Project AutomationClient.Shared supports: net6.0-windows10.0.19041 (.NETCoreApp,Version=v6.0)
C:\Users\danis\Desktop\11_05_2022_unc client check\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)
PS C:\Users\danis\Desktop\11_05_2022_unc client check\AutomationClient\AutomationClient.MAUI> msbuild /t:restore AutomationClient.MAUI
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1009: Project file does not exist. Switch: AutomationClient.MAUI PS C:\Users\danis\Desktop\11_05_2022_unc client check\AutomationClient\AutomationClient.MAUI>
What do I miss ?
Update when I use 4 -2 separate restore and then publish commands it works-:) Need to add .csproj msbuild /t:restore AutomationClient.MAUI.csproj with dotnet build is not working
Another issue: On window server 2012 R2 the MSIX is not open ? Is it a bug or need to do something else ? This is my app manifest in Window platform:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="AutomationClient.MAUI.WinUI.app"/>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<!-- The combination of below two tags have the following effect:
1) Per-Monitor for >= Windows 10 Anniversary Update
2) System < Windows 10 Anniversary Update
-->
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>
</assembly>
Description
Publish MAUI Project with project reference To Class library produces errors.
Steps to Reproduce
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