WebHost名称在当前上下文中不存在 [英] The name WebHost does not exists in current context
问题描述
借助以下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
程序集。因此,要解决您的问题,请安装此NuGet软件包,并在指令中将以下 Microsoft.AspNetCore.All
NuGet软件包随附的.AspNetCore 使用
指令添加到源文件中:
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屋!