The name WebHost does not exists in current context

不问归期 提交于 2019-12-06 17:49:53

问题


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.

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();
    }
}

And here is the error message:

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

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


回答1:


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:

using Microsoft.AspNetCore;




回答2:


As CodeFuller's answer indicated the WebHost class is available in the assembly Microsoft.AspNetCore If you don't need everything, you can just get the package Microsoft.AspNetCore.



来源:https://stackoverflow.com/questions/47416289/the-name-webhost-does-not-exists-in-current-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!