dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.84k stars 1.67k forks source link

Blazor Hybrid - Publish error NETSDK1152 for Microsoft.Web.WebView2 using EF Core 8 #20677

Open JanKotschenreuther opened 4 months ago

JanKotschenreuther commented 4 months ago

Description

Whenever the package Microsoft.Web.WebView2 is included, publishing using the dotnet cli fails, because multiple output files are found for Microsoft.Web.WebView2.Core.dll.

image

C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): err
or NETSDK1152: Es wurden mehrere Ausgabedateien für die Veröffentlichung mit demselben relativen Pfad gefunden: C:\Test
Projects\ReproProjects\BlazorHybridApp\obj\Release\net8.0-windows10.0.19041.0\win10-x64\MsixContent\Microsoft.Web.WebVi
ew2.Core.dll, obj\Release\net8.0-windows10.0.19041.0\win10-x64\R2R\Microsoft.Web.WebView2.Core.dll. [C:\TestProjects\Re
proProjects\BlazorHybridApp\BlazorHybridApp.csproj::TargetFramework=net8.0-windows10.0.19041.0]

Disabling the error message using -p:ErrorOnDuplicatePublishOutputFiles=false suppresses the error message, but the application will display no content after starting the published application.

image

Observing the publish output, it does not seem to contain the correct version of Microsoft.Web.WebView2.Core.dll, it is the version of the NuGet-Package but not the one required to correctly run the app.

This is not only an issue for the direct usage but also transient usage of this package. For example, we got EF Core 8 models, which we want to reference and use in our Blazor Hybrid app. But EF Core references Microsoft.Data.SqlClient which references Microsoft.Identity.Client which references Microsoft.Web.WebView2.

Steps to Reproduce

  1. Create .NET MAUI Blazor Hybrid App

image

  1. Add a package reference for Microsoft.EntityFrameworkCore.SqlServer or Microsoft.Data.SqlClient

    • The reproduction project uses Microsoft.Data.SqlClient for reproduction.
  2. Publish the project as described in Publish unpackaged using the dotnet cli using the following script.

    # The script is included in the reproduction project as Publish.ps1
    dotnet publish .\BlazorHybridApp.csproj `
    -o C:\Publish\BlazorHybridApp `
    -c Release `
    -f net8.0-windows10.0.19041.0 `
    -p:WindowsAppSDKSelfContained=true `
    -p:WindowsPackageType=None `
    -p:RuntimeIdentifierOverride=win10-x64 `
    -p:ErrorOnDuplicatePublishOutputFiles=true `
    -p:Version=1.0.8

Link to public reproduction project repository

https://github.com/JanKotschenreuther/ReproProjects/tree/main

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

Do not use the package Microsoft.Web.WebView2 directly or transiently. Pick one of the following actions:

In our case, we cannot make the effort to downgrade back to EF Core 6 with our models.

Similar issues i came accross on recherche:

Relevant log output

No response

drasticactions commented 4 months ago

Looking through this and the related issues, I think the root cause of this is https://github.com/microsoft/microsoft-ui-xaml/issues/5689.

The BlazorWebView uses WebView2 from whichever version of WinUI is referenced by MAUI, and that's where the conflict comes from. If the WinUI issue is fixed, then this should also work, and that's the underlying dependency conflict. I don't think that can be worked around in this repo without hacking the underlying core of WinUI 3, where it should really be fixed.

If you don't depend on WinUI3 controls, you could also use BlazorWebView in WPF and WinForms which shouldn't suffer this limitation from WindowsAppSDK.

JanKotschenreuther commented 4 months ago

Thanks for the hint to Blazor Hybrid in WPF and WinForms. Using WPF, we are able to publish a Blazor Hybrid app. Might be a good workaround until the root problem of this issue is solved. We would be happy to see a solution to the root problem, to be able to completly migrate to MAUI.

eharbitz commented 4 months ago

We have the same issue, and we have temporarily solved it by first setting

<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles> in the .csproj file.

And then, in our pipeline, after the project is published we replace Microsoft.Web.WebView2.Core.dll with the one from the build folder:

cp {build_dir}/Microsoft.Web.WebView2.Core.dll {build_dir}/publish/Microsoft.Web.WebView2.Core.dll

(This bug stops us from publishing a single file unfortunately)

kevinxufei commented 3 months ago

Verified this issue with maui version 8.0.14/8.0.0-rc.2.9530. Can repro this issue.

kgouraw commented 1 week ago

I have these issue with MAUI. I don't see now with updated Visual Studio version 17.10.3. I think it's fixed with MAUI version 8.0.40