Error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

We just had this issue where visual studio helpfully added a local reference rather than going via nuget

<ItemGroup>
  <Reference Include="Microsoft.AspNetCore.Mvc.Core">
    <HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.core\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll</HintPath>
  </Reference>
</ItemGroup>

Removing this and referencing via nuget solved the problem, looks like an issue in Visual Studio 2017.


So I guess I was referencing the dependencies but didn't have them installed for the project.

All I needed to do was run dotnet restore

https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-restore

As stated in the link above this "Restores the dependencies and tools of a project."


Mine was simply that I had not referenced Microsoft.AspNetCore.App in the .csproj file.

I added the reference and it worked:

MyTestProject.csproj

<Project Sdk="Microsoft.NET.Sdk">
  ...
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>
  ...
</Project>