WebHost名称在当前上下文中不存在 [英] The name WebHost does not exists in current context

查看:276
本文介绍了WebHost名称在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助以下docs.microsoft上的帖子,我正在从ASP.NET Core 1.x迁移到v2.0:
https://docs.microsoft.com/zh-cn/aspnet/core/migration/1x-to-2x/

I'm migrating from ASP.NET Core 1.x to v2.0 with the help of following post on docs.microsoft: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/

该帖子中提到的所有更改都差不多完成了。但是有一个错误会引起麻烦。

I'm almost done with all the changes mentioned in that post. But there is one error that is causing troubles.

这是我的Program.cs文件:

Here is my Program.cs file:

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;

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

        public static IWebHost BuildWebHost(string[] args) =>
           WebHost.CreateDefaultBuilder(args)
               .UseStartup<Startup>()
            .ConfigureAppConfiguration((hostContext, config) =>
            {
            // delete all default configuration providers
            config.Sources.Clear();
                config.AddJsonFile("myconfig.json", optional: true);
            })
               .Build();
    }
}

这是错误消息:

Suppression State
Error   CS0103  The name 'WebHost' does not exist in the current context

任何解决方案,解决方法或提示将不胜感激。谢谢。

Any solution, workaround or hint would be highly appreciated. Thanks.

推荐答案

WebHost 类位于 Microsoft Microsoft.AspNetCore.All NuGet软件包随附的.AspNetCore 程序集。因此,要解决您的问题,请安装此NuGet软件包,并在指令中将以下使用指令添加到源文件中:

WebHost class resides Microsoft.AspNetCore assembly that comes with Microsoft.AspNetCore.All NuGet package. So to fix you problem install this NuGet package and add following using directive to your source file:

使用Microsoft.AspNetCore;

这篇关于WebHost名称在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆