Search code examples
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:

  • It does not exist in my .csproj file. (I searched all files in the source dir with findstr and it only returned files in the bin and obj dirs)
  • I can't remember ever adding it
  • I have published my app in the past without problems (passing WACK)
  • When I checkout an old version of my app from source control, I can see the reference also begin present there, with which I wouldn't have been able to push it to the store.

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

  • the nuget packages I have included don't seem to use it
  • the term 'webview2' can't be found anywhere in my sourcecode or the .csproj / .sln file
  • I see the behaviour on both VS2019 and VS2022 latest versions
  • I disabled all my VS extensions, but no luck.

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.