FSharp.Mobile.Templates icon indicating copy to clipboard operation
FSharp.Mobile.Templates copied to clipboard

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

Open oleksandrmeister opened this issue 3 years ago • 11 comments

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

oleksandrmeister avatar Jul 21 '22 10:07 oleksandrmeister

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

TimLariviere avatar Jul 26 '22 08:07 TimLariviere

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

ChristophSchmidpeter avatar Aug 12 '22 17:08 ChristophSchmidpeter

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

ChristophSchmidpeter avatar Aug 12 '22 17:08 ChristophSchmidpeter

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.

PureWeen avatar Sep 20 '22 14:09 PureWeen

@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?

WillEhrendreich avatar Nov 11 '22 17:11 WillEhrendreich

@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.

TimLariviere avatar Nov 13 '22 08:11 TimLariviere

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?

WillEhrendreich avatar Nov 14 '22 22:11 WillEhrendreich

@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:

  • Create your project using the fabulous-mauicontrols template
  • Add a C# library to the solution (eg. YourApp.WinUI)
  • Change the C# target to net7.0-windows.10-xxx (xxx is your WinSDK version, check the MAUI project file)
  • Copy App.xaml and App.xaml.cs (from MauiLib1\Platforms\Windows\) of @PureWeen's zip file
  • Paste them directly inside YourApp.WinUI
  • Edit YourApp.WinUI.csproj and add <DefineConstants>DISABLE_XAML_GENERATED_MAIN;$(DefineConstants)</DefineConstants> under the first <PropertyGroup> tag
  • Change the namespace's name of those files (search for both strings MauiApp56 and MauiLib1) to match yours.
  • Edit the file YourApp.fsproj
  • Under <ItemGroup Condition=" ... == 'windows' ">, remove both App.xaml and App.xaml.fs
  • Add a new tag <Compile Include="$(WindowsProjectFolder)App.fs" />
  • Create the file YourApp\Platforms\Windows\App.fs and add the following content:
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 avatar Nov 15 '22 09:11 TimLariviere

@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 ¯\(ツ)

TimLariviere avatar Nov 16 '22 08:11 TimLariviere

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 avatar Nov 16 '22 14:11 WillEhrendreich

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.

WillEhrendreich avatar Nov 16 '22 15:11 WillEhrendreich