dotnet / MobileBlazorBindings

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

Hybrid/WebView UWP Problems in Upgrading existing Project #279

Open MichaelPeter opened 3 years ago

MichaelPeter commented 3 years ago

Hi I am currently trying to add MobileBlazorBindings to a existing Xamarin.Forms Project with an UWP Project.

I am Using Xamarin Forms 5.0.0.1829-pre6

I had serveral issues here and I wanted to mention them:

I think all of them happen because after adding the BlazorMobileBindings NuGet package for some reason visual studio thinks all the Plattform specific .csproj files are NetStandard .csproj files and not anymore NetFramework .csproj files, since Visual Studio is confused by the Compile-tags in the .csproj and it tries to import Microsoft.CSharp.target multiple times.

First I had the following Problem with the UWP Project, this problem reoccured after a while when trying to compile:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\PreviewCommunity\MSBuild\Current\Bin\Microsoft.CSharp.targets" cannot be imported again. It was already imported at "C:\Program Files (x86)\Microsoft Visual Studio\2019\PreviewCommunity\MSBuild\Microsoft\WindowsXaml\v16.0\8.21\Microsoft.Windows.UI.Xaml.CSharp.targets (54,5)". This is most likely a build authoring error. This subsequent import will be ignored. [D:\Projects\MyMusicEverywhere\MyMusicEverywhere\MyMusicEverywhere.UWP\MyMusicEverywhere.UWP.csproj] MyMusicEverywhere.UWP

This got for some reason away after chaging the minium UWP Version of the UWP Project, like suggested in a stackoverflow post, after searching for hours this made the error vanish for one or two builds just to reappear again.

When I then tried to compile this error happend: Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were:

I added EnableDefaultCompileItems=false to the netframework style .csproject. Not shure why this is tried with the project.

Then this resulted in this error:

"ResolvePackageAssets" task was not given a value for the required parameter "TargetFramework". 

in the UWP Project.

This I think also prevents the adding of Microsoft.BlazorMobileBindings.WebView.Windows to the UWP Project. Is Latter currently even supported? I saw in a sample project this reference is also not added?

I saw the samples have in the Main Project in the csproject <Project Sdk="Microsoft.NET.Sdk.Razor"> this is mandatory instead of the <Project Sdk="Microsoft.NET.Sdk"> in normal Xamarin Forms Projects?

Is this related, since the MobileBindings and NetSdk have some NetCore dependencies?

A UWP sample for an Hybrid App would be highly appriciated.

After removing all dependencies and restarting Visual Studio a few times everything worked again.

Greetings Michael

Eilon commented 3 years ago

I haven't tried UWP for this yet but I can take a look. Can you publish your project to a GitHub repo so I can take a look?

MichaelPeter commented 3 years ago

Hello Eilon,

thanks for the quick response

I cannot upload my project, but I uploaded a project where it can reproduced: https://github.com/MichaelPeter/BlazorMobileUWPHybridTest

Essentially I just created a new xamarin forms project with uwp added Microsoft.MobileBlazorBindings to the main project addded Microsoft.MobileBlazorBindings.WebView.Windows to the UWP Project.

and then this errors happen on compile: (Visual Studio 2019 Preview 16.9.0 Preview 2.0) Errors Visual Studio

also I cannot add webview references to any other project

When I compared my UWP Project and the UWP samples in the push of @chrisevans9629 https://github.com/chrisevans9629/MobileBlazorBindings/blob/addedUwpSample/samples/MobileBlazorBindingsTodoSample/MobileBlazorBindingsTodo.UWP/MobileBlazorBindingsTodo.UWP.csproj

I noticed amoung other things mine had: <EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile> and his had

  <PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>

not sure if it is related.

Eilon commented 3 years ago

Oops I think I missed something earlier. There isn't currently a build of Mobile Blazor Bindings for UWP on Windows, only WPF on Windows. It's something we could probably add, but I wouldn't expect the WebView.Windows package to work in UWP.

MichaelPeter commented 3 years ago

Hello Elliot,

thanks for the response, can you tell us about the Plans/Roadmap for mobile bindings and windows store/xbox?

Will there be a way for windows store/Xbox apps to run mobile blazor bindings? Maybe with winui 3 or the first preview for system.Maui? Or is there a uwp version to come?

What is the issue here, Franken-csproj instead of sdk-csproj?

Why I am asking this:

I want to build one Blazor Hybrid UI in Html and CSS and Run it in the Browser, Windows Store, Android, iOS, MacOs. Some elements will maybe use Native Controls. Essentially what I can do today already with React/React Native and Angular/Ionic but in .NET.

BlazorMobile offered this already but they stopped development and said to switch to MobileBlazorBindings.

Thanks for the Answer Greetings Michael

Eilon commented 3 years ago

We're working on some updates that will enable Windows Store via UWP and also making sure that Apple App Store support is all there.

I will work with my team to see if we can get some sort of proper roadmap published and I will share when it is available.

MichaelPeter commented 3 years ago

Hello Eilon, sorry for misspelling your name.

That sounds great! Thank you for the info :D