Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
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?
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://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."
–
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>
–
–
–
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.
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>
<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>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.2.0" />
</ItemGroup>
Solved the issue as @dave-glassborow answered
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>
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.
–
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!
What ended up working for me were the following steps:
Unload project and edit .csproj file as user875234 recommended in another answer
Reload and rebuild project (this resulted in different errors for me)
Unload project and undo edits to .csproj file
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!
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.