Windows应用商店应用程序和F# [英] Windows Store Apps and F#
问题描述
我正在尝试使用F#创建可移植的库以用于Windows Store应用程序.我用一个类创建了一个fs文件:
I am trying to create a portable library using F# to use with Windows Store apps. I created one fs file with one class:
module FunctionalRT
open System.Net
open System.IO
type WebHelper =
static member DownloadStringAsync (url:string) = async {
let req = HttpWebRequest.Create(url)
use! resp = req.AsyncGetResponse()
use stream = resp.GetResponseStream()
let reader = new StreamReader(stream)
let s = reader.ReadToEnd()
return s
}
我在Windows Store应用程序中毫无问题地引用了该库.但是问题是,我不能访问FunctionalRT
模块,也不能访问WebHelper
类.当我编写using FunctionalRT
或尝试使用FunctionalRT.WebHelper.FunctionalRT
时,编译器会抱怨它不知道.可能是什么问题?
I referenced this library in my Windows Store app with no problems. But the problem is, I cannot access the FunctionalRT
module neither the WebHelper
class. When I write using FunctionalRT
or try to use FunctionalRT.WebHelper.FunctionalRT
, the compiler complains it does not know it. What may be the problem?
经过几次清洗和清理后,我得到了
After a few buidls and cleans I get
The type 'Microsoft.FSharp.Control.FSharpAsync`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'FSharp.Core, Version=2.3.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. C:\Users\Igor\Documents\Visual Studio 2012\Projects\App3\App3\GroupedItemsPage.xaml.cs 46 13 App3
添加对C:\Program Files (x86)\MSBuild\..\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\.NETPortable\FSharp.Core.dll
的引用解决了上述错误消息,但还有一个错误提示
Adding a reference to C:\Program Files (x86)\MSBuild\..\Reference Assemblies\Microsoft\FSharp\3.0\Runtime\.NETPortable\FSharp.Core.dll
solved the above error message, but there is another one
Cannot await 'Microsoft.FSharp.Control.FSharpAsync<string>'
推荐答案
您必须在Windows Store应用中引用此库才能使其正常工作:
You have to reference this library in your Windows Store app to make it work:
C:\ Program Files(x86)\ Reference 程序集\ Microsoft \ FSharp \ 3.0 \ Runtime.NETPortable \ FSharp.Core.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\3.0\Runtime.NETPortable\FSharp.Core.dll
关于该FSharpAsync类,请参见以下线程:
从C#中引用异步F#数据类型
And regarding that FSharpAsync class, see this thread:
Referencing Asynchronous F# datatype from C#
您可以使用FSharpAsync类型的静态方法来等待返回的对象.
You could use static method of the FSharpAsync type for awaiting the returned object.
这篇关于Windows应用商店应用程序和F#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!