是否可以使用F#开发Windows8万能App

Is it possible to use F# to develop Windows 8 Universal App

我想使用 F# 开发 windows 8.1 通用应用程序。所以我创建了 F# 可移植库。但不幸的是我无法在其上打开 Windows.Storage 命名空间。

然后我创建了 C# Windows 应用程序 Class 库,我在其中实现了我需要的功能:

 public static async Task<string> ReadFileToString(string filename)
 {
        StorageFile file = await StorageFile.GetFileFromPathAsync(filename);
        string fileContent =  "";
        fileContent = await FileIO.ReadTextAsync(file);

        return fileContent;
 }

然后我想将我的 F# 可移植库中的引用添加到此 C# 库,但收到错误消息,即

"it is impossible because the project is designed for platform (.NETCore) which different from current (.NETPortable)"

可以用F#开发windows8个通用app吗?

这是我找到的解决方案。

  • 使用 NuGet 安装 PCLStorage F# 可移植库和 Windows 8.1 商店应用程序 (!)
  • 在 F# 库中设置 "Copy to Local" = False (!)

这是 f# 库的代码:

namespace PortableLibrary1

open PCLStorage

type MyClass() =
    member this.Do (filename : string) (text : string) = 
        let folder = FileSystem.Current.LocalStorage       
        async {
            let! result = Async.AwaitTask(folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting))
            result.WriteAllTextAsync(text) |> ignore        
        } |> Async.RunSynchronously

这是一个 C# 商店应用程序代码:

 private void Button_Click(object sender, RoutedEventArgs e)
 {
    MyClass cls = new MyClass();             
    cls.Do("uuu.ii", "message of me");
 }