53

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?

15 Answers 15

28

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.

3
  • 1
    In mine, this was missing: <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" /> altogether. I added it back and it worked. Thanks for giving me a clue as to where to look.
    – Eric
    Jul 12, 2018 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 1, 2018 at 17:02
  • I just added the package I needed which for me was <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
    – Paul C
    Feb 19, 2021 at 12:03
24

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://learn.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."

2
  • 10
    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, 2017 at 21:03
  • 3
    I get 'All packages are already installed and there is nothing to restore.' Aug 7, 2018 at 13:35
20

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>
4
  • 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? Jun 25, 2019 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? Sep 25, 2019 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, 2019 at 13:18
  • Fixed the issue Oct 22, 2020 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.

6

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>
1
3

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

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.

1

Just add Microsoft.AspNetCore.WebUtilities nuget package

1
  • I then get this error 'the type or namespace Mvc does not exist in the namespace AspNetCore'
    – niico
    May 12, 2020 at 11:14
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!

1

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

1

Just adding the Microsoft.AspNetCore.Mvc nuget package fixed it for me.

1

What ended up working for me were the following steps:

  1. Unload project and edit .csproj file as user875234 recommended in another answer
  2. Reload and rebuild project (this resulted in different errors for me)
  3. Unload project and undo edits to .csproj file
  4. Reload and rebuild project

Along the way, I did also run dotnet restore a couple of times, so that may have also helped somehow.

Hopefully this helps someone with a similar issue to me!

0

For me, using net6, the issue was that Rider did generate this reference in my client library csproj:


<ItemGroup>

    <Reference Include="Microsoft.AspNetCore.Mvc.Core">

      <HintPath>..\..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\6.0.18\Microsoft.AspNetCore.Mvc.Core.dll</HintPath>

    </Reference>

  </ItemGroup>

When our build pipeline was running, it was not able to find it so I replaced it with:


<ItemGroup>

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

  </ItemGroup>

source: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-7.0&tabs=visual-studio#use-the-aspnet-core-shared-framework

0

Add these references to your library when you are using a ASP NET Core library with controllers/MVW:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.9" />
</ItemGroup>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.