首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从f#访问.net asp.core库中的静态类

如何从f#访问.net asp.core库中的静态类
EN

Stack Overflow用户
提问于 2018-07-07 23:12:42
回答 1查看 131关注 0票数 1

我正在尝试翻译以下内容:

代码语言:javascript
复制
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace AspNetCoreDotNetCore2App
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }
}

转到f#

我想出了这个:

代码语言:javascript
复制
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting

type Program =     
    static member BuildWebHost =
        fun (args : string []) ->
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build()

    static member Main(args : string []) =    
        BuildWebHost(args).Run() 

但在构建时出现错误:

代码语言:javascript
复制
D:\documents\code\rhea\Program.fs(318,13): error FS0039: The value, namespace, type or module 'WebHost' is not defined.
 Maybe you want one of the following:   IWebHost   WebHostBuilder   WebHostDefaults   WebHostExtensions   Web
D:\documents\code\rhea\Program.fs(323,9): error FS0039: The value or constructor 'BuildWebHost' is not defined. Maybe y
ou want one of the following:   Builder   IWebHost

下面是WebHost的文档:https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.webhost?view=aspnetcore-2.1

EN

回答 1

Stack Overflow用户

发布于 2019-09-05 02:29:42

代码语言:javascript
复制
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting

let createWebHostBuilder args =
   WebHost
       .CreateDefaultBuilder(args)
       .UseStartup<Startup>();

[<EntryPoint>]
let main args =
    CreateWebHostBuilder(args).Build().Run()
    0
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51224438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档