user10133969
user10133969

Reputation:

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

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

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

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' 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);

Upvotes: 0

Views: 5326

Answers (1)

alsami
alsami

Reputation: 9815

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.

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

Upvotes: 1

Related Questions