gpt4 book ai didi

f# - FS2024 TypeProvider 使用 PCL 项目时出现静态链接错误

转载 作者:行者123 更新时间:2023-12-02 09:23:16 29 4
gpt4 key购买 nike

它正在尝试为 Xamarin.Forms 创建 TypeProvider,但一直受到 FS2024 错误的困扰。

  • 从 Xamarin.Forms 的 XAML 解析自己的库
  • 将 x:Name 分配给 Propertis

`F#

type MainPage = Moonmile.XamarinFormsTypeProvider.XAML<"MainPage.xaml">
// made btn1 and text1 propertis

type MainPageEx(target:MainPage) =
let mutable count = 0
do
// When set event to btn.Clicked, happen FS2024 error.
// If this event is comment out, it success build.
target.btn1.Clicked.Add( fun e ->
count <- count + 1
target.btn1.Text <- "Clicked " + count.ToString())
// Property is success
member this.CurrentPage
with get() = target.CurrentPage

当您指的是属性时,通常可以构建和操作。但是Xamarin.Forms的内部类如Button.Clicked,如果尝试访问,就是构建错误。

错误代码示例 https://github.com/moonmile/SimpleEventTypeProvider

为 XamarinFormsTypeProvider 编写代码github.com/moonmile/XamarinFormsTypeProvider

也许,我怀疑在生成 Native TypeProvider 和 Xamrin.Forms.Core PCL 的过程中会出现不一致的情况。

F# Compiler for F# 3.1 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License my error!!!
isMscorlib: true
name: "System.Runtime"
PrimaryAssembly.DotNetCore.Name: "System.Runtime"
PrimaryAssembly.Mscorlib.Name: "mscorlib"

parameter error FS2024: Static linking may not use assembly that targets different profile.

这是为了操作它们正常工作的属性,也许是为了 MVVM。但是我正在尝试实现一种分配给 Button.Clicked 事件的方法如果可能的话,如类似代码隐藏的建筑物所示。

有解决办法吗?

就 WPF 中的 XAML 而言,这样的效果如何?github.com/fsprojects/FsXaml

最佳答案

这个答案不能保证是正确的,但它至少应该帮助您指出正确的方向。

要做的第一件事是确保您已安装最新的 Visual F# Tools Build,因为这会添加与 PCL 配置文件兼容的 FSharp.Core(您可以在此处找到它:( https://visualfsharp.codeplex.com/ )。安装后,您将需要引用 Profile78 或 Profile259 FSharp.Core.dll(在我的计算机上,这些位于:“C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp .NETPortable\2.3.5.0”和“C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp.NETPortable\2.3.5.1”分别)。

安装完成后,下一步要做的就是确保您的 PCL 项目在其项目文件中包含以下内容(这告诉 MSBuild/xBuild 这些项目是 PCL 库,并且它们是 F# 项目):

<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{F2A71F9B-5D33-465A-A702-920D77279786}</ProjectTypeGuids>

完成后,您将需要选择 Profile78 或 Profile259(我建议选择 78,因为当前的 Xamarin.Forms nuget 包不支持 259)。

完成后,您应该能够构建并运行,并且应该消除错误。

关于f# - FS2024 TypeProvider 使用 PCL 项目时出现静态链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25175031/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com