fabulous-dev / FSharp.Mobile.Templates

Mobile templates for .NET 8.0 / F# 8.0
103 stars 5 forks source link

Parameter name: The language 'F#' is not supported #21

Open oleksandrmeister opened 2 years ago

oleksandrmeister commented 2 years ago

I have new templates installed but after creating the new maui-fsharp application and running build command I have the following error:

PS C:\temp\maui\TestApp> dotnet build -c Release MSBuild version 17.3.0-preview-22329-01+77c72dd0f for .NET Determining projects to restore... All projects are up-to-date for restore. You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview TestApp -> C:\temp\maui\TestApp\bin\Release\net6.0-maccatalyst\maccatalyst-x64\TestApp.dll TestApp -> C:\temp\maui\TestApp\bin\Release\net6.0-ios\iossimulator-x64\TestApp.dll EXEC : Xaml Internal error : Specified argument was out of the range of valid values. [C:\temp\maui\TestApp\TestApp.fsp roj] Parameter name: The language 'F#' is not supported

TimLariviere commented 2 years ago

I only see this error on Windows. I think it's a problem with the Windows target of MAUI where F# is not allowed...

If you don't plan on targeting Windows, I would recommend you remove the net6.0-windows target in the fsproj file

ChristophSchmidpeter commented 2 years ago

Still reproducible (100%) with VS 17.3.0 on Windows.

ChristophSchmidpeter commented 2 years ago

I think it's a problem with the Windows target of MAUI where F# is not allowed...

I agree; it indeed seems to be a problem within MAUI itself. So I think we should file a bug report in the MAUI repo if it hasn't already been done yet. Is there a respective ticket in the MAUI repo yet? If not, I can file one.

Edit: I have created a MAUI ticket

PureWeen commented 2 years ago

mauihead.zip

Not 100 percent ideal but I have a workaround here that we could put into the templates for now. Basically it just adds a referenced project that's C# so that WinUI can generate its code inside there and then the head project can just use that. I asked the WinUI team if there's a better way to go about doing this but for now this seems to work alright.

WillEhrendreich commented 1 year ago

@PureWeen How would you use fabulous with the mauihead project you've linked? I'm rather new and I'm interested in trying to build a small crud app with this, but I'm more interested in doing it MVU vs MVVM, so I'm not entirely sure how to bridge the gap? Or is it not entirely possible yet?

TimLariviere commented 1 year ago

@WillEhrendreich You should be able to do a full MVU MAUI app using Fabulous.MauiControls (templates here)

I believe the head project shared by @PureWeen is literally just a drop-in to the F# MAUI template that can be found in this repository or in Fabulous.MauiControls.Templates. The current F# template can't compile for net7.0-windows because of toolchain issue, but if you add a C# windows project that reference the F# lib, it will work.

WillEhrendreich commented 1 year ago

hey @TimLariviere , thanks for responding!

I'm hoping you can give an example..

I have no idea how to make this work.. I've been trying all day to do what you're saying.. I don't know what I'm missing. @PureWeen 's template is an fsharp and csharp project on maui that interact with each other, but I have no idea how to integrate it with Fabulous.

What do I replace with what.. and where?

TimLariviere commented 1 year ago

@WillEhrendreich I didn't had time to prepare you a full sample, but I understand better how to make it work.

Those steps should lead you to a working WinUI project:

namespace YourApp.WinUI

open Microsoft.UI.Xaml
open Microsoft.Maui
open Microsoft.Maui.Controls.Xaml
open YourApp

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
type App() =
    inherit YourApp.WinUI.App()

    override this.CreateMauiApp() = MauiProgram.CreateMauiApp()

This should let you build for WinUI

TimLariviere commented 1 year ago

@WillEhrendreich I created this library to take care of most of the steps above: https://github.com/fsharp-mobile/FSharp.Maui.WinUICompat

The idea is to remove the App.xaml and App.xaml.fs files from Platforms\Windows in the MAUI project, add this package and create a new file call App.fs in Platforms\Windows with this:

type App() =
    inherit FSharp.Maui.WinUICompat.App()

    override this.CreateMauiApp() = YourApp.MauiProgram.CreateMauiApp()

module Main =
    [<EntryPoint; STAThread>]
    let main args =
        FSharp.Maui.WinUICompat.Program.Main(args, typeof<App>)

This will let the app compile and run. But when trying it, it was crashing at runtime because Microsoft.ui.xaml.dll was not found. Following a comment about this issue on GitHub, I installed the C++ redistribuable. ... and now I can't even compile because the NuGet package winappsdk tries to include a C# file into the F# project ¯\(ツ)

WillEhrendreich commented 1 year ago

Yeah, I've been chasing this down all yesterday. I got exactly as far as that, the exact library was "missing". I was going to try to comment back with how far I got, but I guess you got the same result. Haha.

WillEhrendreich commented 1 year ago

https://github.com/microsoft/WindowsAppSDK/issues/1762 <- here is the issue i was trying to reference to help resolve things but have as of yet been unsuccessful.