37

I'm trying to upgrade the following template project to ASP.NET Core 1.1: https://github.com/wilanbigay/aspnet-core-aurelia-typescript-starter

After running dotnet migrate the project.json file has been dropped in favour of the new csproj file.

Using Visual Studio Code and the Nuget4Code extension I've upgraded all components to ASP.NET Core 1.1.

The CsProj now contains entries like so:

<ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Sdk.Web">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.1.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc">
      <Version>1.1.0</Version>
    </PackageReference>

However I have compilation issues. It seems the AspNetCore namespace can't be found. I'm getting the error

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

I'm not sure how I can check references like I used to be able to in Visual Studio in the references section. How can I resolve this?

Chris Nevill
  • 5,076
  • 10
  • 39
  • 72

11 Answers11

23

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.

Dave Glassborow
  • 2,707
  • 1
  • 24
  • 24
  • In mine, this was missing: altogether. I added it back and it worked. Thanks for giving me a clue as to where to look. – Eric Jul 12 '18 at 12:36
  • I'd had a few of these references - seems like they were added automatically as part of the project template?! Was only an issue when it came to restoring/building on TeamCity. Removing those references and installing them via NuGet fixed it for me. – Tom Nov 01 '18 at 17:02
  • I just added the package I needed which for me was – Coops Feb 19 '21 at 12:03
22

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."

Chris Nevill
  • 5,076
  • 10
  • 39
  • 72
  • 9
    I'm running .net core 2 where building should restore - ive also done a nuget package restore - and I'm still getting this and many other Identity related errors – niico Nov 12 '17 at 21:03
  • 2
    I get 'All packages are already installed and there is nothing to restore.' – JsonStatham Aug 07 '18 at 13:35
11

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>
user875234
  • 1,905
  • 2
  • 22
  • 38
  • This fixed my issue. I created the project with `dotnet new web`, perhaps should have used `dotnet new webapp` to add this automatically to .csproj? – suspicious_williams Jun 25 '19 at 10:32
  • when i double click the .csproj file it appears to open the entire project - how would i edit the .csproj file? you're like saying open the project file in text edit? – user1709076 Sep 25 '19 at 22:33
  • Yes. If you are in visiual studio you can right click the project (in solution explorer) and select edit project or unload project. If you aren't in visual studio open it with VS Code or Notepad++ and you can edit it like any other text file. – user875234 Sep 27 '19 at 13:18
  • Fixed the issue – Sagar Khatri Oct 22 '20 at 10:55
7

I ran into this problem as well, and in my case the proper packages were installed and all my *.csproj looked correct, but one of the projects in my solution still gave me this error.

A plain dotnet restore didn't do the trick for me. I had to force a reevaluation of all dependencies like so:

dotnet restore --force-evaluate

From the dotnet manual:

Forces restore to reevaluate all dependencies even if a lock file already exists.

A couple of seconds later, my compiler stopped giving me this error.

D.Nielsen
  • 116
  • 1
  • 8
2

Changing

<ItemGroup>
  <Reference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore">
    <HintPath>..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.identity.entityframeworkcore\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Identity.EntityFrameworkCore.dll</HintPath>
  </Reference>
</ItemGroup>

To

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.2.0" />
</ItemGroup>

Solved the issue as @dave-glassborow answered

Khongor Bayarsaikhan
  • 1,266
  • 1
  • 10
  • 16
1

My problem was that a project in the solution was not building properly, so it could not be referenced by other projects in the solution.

The solution was to update Visual Studio (I updated from version 15.5.6 to version 15.9.1). Here is a link to Microsoft's VS Downloads page.

Eric
  • 12,320
  • 4
  • 53
  • 63
1

I have found this problem when upgrading libraries from .NET Standard 2.0 to 2.1 or .exe's from .NET Core 2.2 to 3.1.

The best bet is just to redo all the NuGet includes for the project from scratch. Open the .csproj file in a text editor, and find the section

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

and remove all of it, back to

  <ItemGroup>
  </ItemGroup>

then re-open the solution and reinstall all, and only, the required NuGet packages.

This fixes the problem and can help to clean up any unused package cruft as well!

MikeBeaton
  • 2,077
  • 2
  • 26
  • 36
0

Just add Microsoft.AspNetCore.WebUtilities nuget package

ukod
  • 119
  • 2
  • 9
  • I then get this error 'the type or namespace Mvc does not exist in the namespace AspNetCore' – niico May 12 '20 at 11:14
0

Adding NuGet package Microsoft.AspNetCore.Mvc.ViewFeatures fixed it for me

niico
  • 8,315
  • 18
  • 65
  • 125
0

I had this error upgrading a .NET Core v2.2 project to v3.1. Specifically, a unit testing project was giving the error, that didn't directly use the AspNetCore package.

The solution is described here, and consists of modifying the project file to add a <FrameworkReference> tag:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>
Nick
  • 3,738
  • 33
  • 53
0

I just ran into this with dotnet core 5.0. My csproj looked like:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>

But needed to look like (note the project element's sdk attribute):

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>
djeikyb
  • 4,000
  • 3
  • 32
  • 37