visual-studiosdkwebview2

How do I stop Visual studio from adding reference to WebView2?


I have a problem pushing an update of my Xamarin.Forms.UWP to the store. It does not pass the WACK test because I have a reference to Microsoft.Web.WebView2.Core in my project. I do not know how this reference was added, and I am unable to remove it.

enter image description here

As far as I know, you can manually add/remove references, and they will be added to/removed from the .csproj file. But this reference is different. I am able to visually remove it, but the .csproj file does not change. Also when the project is unloaded-reloaded, it appears again. Cleaning or removing the bin/obj dir does not affect this behaviour.

I believe something in my environment is adding this reference because:

I am clueless on what makes this reference being automatically added.

I tried to create a new Xamarin.Forms.UWP app, and there the references does not seem to be added. It might be because of the newer template.

Maybe the following will provide a clue, besides the bin folder of my project, this dll lives on my pc in the following locations:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\libexec\git-core\Microsoft.Web.WebView2.Core.dll C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\Asal\TokenService\Microsoft.Web.WebView2.Core.dll C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\Asal\Microsoft.Web.WebView2.Core.dll C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Web Live Preview\Microsoft.Web.WebView2.Core.dll C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw64\libexec\git-core\Microsoft.Web.WebView2.Core.dll C:\Users\sjors\AppData\Local\Atlassian\SourceTree\git_local\mingw32\libexec\git-core\Microsoft.Web.WebView2.Core.dll C:\Users\sjors.nuget\packages\microsoft.web.webview2\1.0.1020.30\lib\net45\Microsoft.Web.WebView2.Core.dll C:\Users\sjors.nuget\packages\microsoft.web.webview2\1.0.1020.30\runtimes\win-x86\native_uap\Microsoft.Web.WebView2.Core.dll C:\Users\sjors.nuget\packages\microsoft.web.webview2\1.0.1020.30\lib\netcoreapp3.0\Microsoft.Web.WebView2.Core.dll C:\Users\sjors.nuget\packages\microsoft.web.webview2\1.0.1020.30\runtimes\win-arm64\native_uap\Microsoft.Web.WebView2.Core.dll C:\Users\sjors.nuget\packages\microsoft.web.webview2\1.0.1020.30\runtimes\win-x64\native_uap\Microsoft.Web.WebView2.Core.dll

My main suspect currently is an upgrade I recently did on the Microsoft Windows SDK, also related to WACK problems. Unfortunately, uninstalling the latest version did not fix my problem.

Also I just found this thread that is quite similar but different: https://github.com/MicrosoftEdge/WebView2Feedback/issues/1722

This thread also mentions the reference being added: "The referenced component could not be found" but VS keeps re-adding the reference after I remove it


Solution

  • The cause seems to be that because I use lottie, I have to add a reference to the Microsoft.Ui.Xaml nuget in order to pass WACK. Apparently I had upgraded this package to a prerelease version and this new version has introduced a dependency on WebView2, dynamically adding the dll on build.

    Downgrading the Microsoft.Ui.Xaml package to 2.7.1 and upgrading the UWP minimum build target to build 19041 to work with com.arinbnb.xamarin.forms.lottie v4.0.11 fixed it for me.