4
votes

I'm learning .net core and started with .net core 2.2

I'm following this tutorial. https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.2&tabs=visual-studio

I did below.

-> Created New ASP.NET Core Web Application project and selected API template with Asp.NET core 2.2 version -> Build the application

There is a build error with the default application created.

The error is "The name WebHost doesn't exist in the current context."

I haven't made any changes to the code yet and the namespace Microsoft.AspNetCore; is present in the using statement.

I'm not sure what i'm missing here. Can you please help?

5
I am able to build the app as outlined above. VS 2017 15.9.2 Enterprise.JamieMeyer
I'm using VS 2017 15.9.3 Professional. @Khai I don't thing this is a duplicate. The link talks about migration. But I'm not migrating and I have used the name space Microsoft.AspNetCore as mentioned in the link.NewBie
Can you run dotnet --version and dotnet --info then check your NetCore version of runtime and SDK?Khai Nguyen
I'm having the same issueAlessandro R

5 Answers

2
votes

I ran into the same issue and here is my workaround. The MS documentation says to update the TFM and then make sure there is no version for the package reference Microsoft.AspNetCore.App.

To workaround this issue:

  • run Uninstall-Package Microsoft.AspNetCore.App in the package manager console
  • then run Install-Package Microsoft.AspNetCore.App

This will add the package reference with the version attribute:

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />

I had mixed results after removing the Version attribute from the package reference. Initially I was getting build errors, but I can't reproduce the error anymore - it works without the Version attribute.

1
votes

The are the steps I recommend to solve this issue based on my experience and the experience of others.

  1. Ensure you have the latest Visual Studio and necessary SDK.
  2. Ensure you have the required dotnet version via dotnet --version. This should be installed with VS, but if you aren't installing VS then you still need to update dotnet versions.
  3. If you are using ReSharper, disable it or download the latest update. There is a GitHub issue you can refer to for more information.
  4. Try running dotnet restore. If you see a message like Permission denied to modify the 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder' folder. then your issue is able to be solved by deleting the NugetFallbackFolder folder. See GitHub issue.
  5. If you are still having issues, good luck and comment with your solution once you figure it out.
0
votes

I had the same problem but I found the solution: In properties of the project select as Target framework one of the .NET Core framework, ex. .NET Core 2.1, save changes. Then select correct framwork - .NET Core 2.2 Rebuild project. That's all.

0
votes

I solved it by deleting C:\Program Files\dotnet\sdk\NuGetFallbackFolder then run dotnet build in administrator cmd

0
votes

I had the same issue. Just simply deleting the Object Folder helped.