WebHost name does not exist in current context

I am switching from ASP.NET Core 1.x to v2.0 using the following post on docs.microsoft: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to -2x /

I am almost done with all the changes mentioned in this post. But there is one mistake that causes problems.

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 much appreciated. Thank you

+14
source share
3 answers

WebHostthe class contains the assembly Microsoft.AspNetCorethat comes with the Microsoft.AspNetCore.AllNuGet package . Therefore, to fix the problem, install this NuGet package and add the following directive usingto the source file:

using Microsoft.AspNetCore;

+19

CodeFuller, WebHost Microsoft.AspNetCore , Microsoft.AspNetCore.

0

Add CreateWebHostBuilder(args).Build()instead BuildWebHost(args).

-1
source

Source: https://habr.com/ru/post/1689635/


All Articles