当前上下文中不存在名称 WebHost [英] The name WebHost does not exists in current context
问题描述
借助 docs.microsoft 上的以下帖子,我正在从 ASP.NET Core 1.x 迁移到 v2.0:https://docs.microsoft.com/en-us/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.AspNetCore.All<附带的
Microsoft.AspNetCore
程序集/code> NuGet 包.因此,要解决您的问题,请安装此 NuGet 包并将以下 using
指令添加到您的源文件中:
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屋!