dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 168 forks source link

`dotnet new blazorhybrid -o FirstBlazorHybridApp` creates a non-working project? #416

Closed BenMakesGames closed 2 years ago

BenMakesGames commented 2 years ago

I'm trying to create a minimum project demonstrating another issue, but the command for creating new projects, found here: https://docs.microsoft.com/en-us/mobile-blazor-bindings/walkthroughs/build-first-hybrid-app isn't working:

image

Eilon commented 2 years ago

Hi @BenMakesGames , that's certainly unexpected. Can you confirm that you have Edge WebView2 installed? You can get it from https://developer.microsoft.com/microsoft-edge/webview2/ (use one of the "Evergreen" options).

BenMakesGames commented 2 years ago

I've got another MBB project going that works. I've been comparing the code trying to see what's different. made a few changes to the one created with dotnet new, but none of the changes have worked yet.

BenMakesGames commented 2 years ago

tried reinstalling WebView2 anyway; no change

BenMakesGames commented 2 years ago

not sure what to do at this point. I've changed everything I can think of to match my existing MBB project, including many things I'm sure wouldn't matter.

I primarily use Rider, but I also tried opening the solution in VS 2019 to see if that would somehow help, but that hasn't. I've deleted bin and obj dirs, and re-ran nuget restore...

I have other things I need to do today, and am on vacation next week. I'll have to revisit later.

Eilon commented 2 years ago

Oh hold on, this sounds like #403 ! To work around that, you can add this to the Windows project CSPROJ file:

    <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.961.33" />

And that will bring in the updated WebView2 component, which apparently fixes the address invalid issue.

Can you try that and see if it works?

BenMakesGames commented 2 years ago

that didn't work on its own, but I played around, and discovered the following:

  1. after adding WebView2 as you instructed, AND upgrading the Xamarin packages to 5.0 in both projects (Windows, and platform-independent), then the project worked!
  2. after adding WebView2 and upgrading the Xamarin packages, and then REMOVING WebView2, it continued to work...
  3. I thought I had previously tried upgrading all the packages before, so I created a SECOND totally-new project, and ONLY upgraded the Xamarin packages, and that DIDN'T work!

I'm not sure why # 2 works; maybe package caches, or not-quite-empty obj/bin dirs, or something.

anyway, I dunno if there's more scenarios that need testing, but it seems like, for me, I need to both add WebView2 and upgrade Xamarin packages to 5.0.

(sorry about the late reply; was on vaca!)

Eilon commented 2 years ago

@BenMakesGames OK well that is very bizarre, then! I'm glad you got it working now. Ultimately the plan is to move this all to .NET MAUI, for which there is already a PR open that I need to review. Hopefully that will resolve many issues.