"WebHost"不包含"CreateDefaultBuilder"的定义 [英] 'WebHost' does not contain a definition for 'CreateDefaultBuilder'

查看:542
本文介绍了"WebHost"不包含"CreateDefaultBuilder"的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我致力于.NET CORE API的迁移. 首先,我有此错误消息:

I work on the migration of an .NET CORE API. Firstly, I have this error message :

名称"WebHost"在当前上下文中不存在

The name 'WebHost' does not exist in the current context

所以Visual Studio建议我使用此命名空间:

So Visual Studio suggest me to have this namespace :

using Microsoft.AspNetCore.Hosting.Internal;

我将其放在文件中,然后显示以下错误消息:

I put it in my file, after that I have this error message :

"WebHost"不包含"CreateDefaultBuilder"的定义

'WebHost' does not contain a definition for 'CreateDefaultBuilder'

我不知道为什么要这么做.我可以帮忙吗?

I don't know why it's doing that. Can I have some help ?

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args);

推荐答案

您需要引用 Microsoft.AspNetCore ,并包含名称空间using Microsoft.AspNetCore;.如果使用模板,则它们通常包括一个元包.根据版本(2.0或2.1)和您的IDE,它可能是 Microsoft.AspNetCore . Microsoft.AspNetCore.App .在那里,您将包含所有必需的软件包.很方便,但是您可能需要手动添加所需的内容.

You need a reference to Microsoft.AspNetCore and include the namespace using Microsoft.AspNetCore;. If you use a template, they usually include a meta-package. Depending on the version (2.0 or 2.1) and your IDE, it either will be Microsoft.AspNetCore.All or Microsoft.AspNetCore.App. There you will have all necessary packages included. Is convenient but you might want to add what you need manually.

Microsoft.AspNetCore.Hosting.Internal 不是您想要的.您在寻找什么在这里.

The suggestion to Microsoft.AspNetCore.Hosting.Internal is not what you are looking for. What you are looking for you find here.

这篇关于"WebHost"不包含"CreateDefaultBuilder"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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