Reputation: 6152
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?
Upvotes: 58
Views: 153531
Reputation: 1
In my case, I removed the line '#using AspNetCore;' from my code, issue resolved.
Upvotes: 0
Reputation: 537
My issue was pretty bizarre. I have compiled this application a million times and didn't add of remove any packages recently. Suddenly, I started getting this error.
I noticed in the error, it also referenced a filename just before it. I went in that file (a class/model) and found a greyed out using AspNetCore;
- I commented it out and have had no further issues.
None of the other solutions mentioned above helped. Some even caused more issues. Good luck!
Upvotes: 2
Reputation: 4134
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>
Upvotes: 1
Reputation: 1484
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>
Upvotes: 2
Reputation: 65
What ended up working for me were the following steps:
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!
Upvotes: 2
Reputation: 6035
Just adding the Microsoft.AspNetCore.Mvc
nuget package fixed it for me.
Upvotes: 2
Reputation: 4589
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>
Upvotes: 6
Reputation: 5198
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>
Upvotes: 5
Reputation: 12729
Adding NuGet package Microsoft.AspNetCore.Mvc.ViewFeatures fixed it for me
Upvotes: 1
Reputation: 126
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.
Upvotes: 7
Reputation: 3867
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!
Upvotes: 1
Reputation: 2517
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>
Upvotes: 23
Reputation: 1704
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
Upvotes: 3
Reputation: 17536
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.
Upvotes: 1
Reputation: 3553
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.
Upvotes: 33
Reputation: 6152
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."
Upvotes: 24