Closed xsqian closed 6 years ago
@Rick-Anderson Any ideas on this?
@xsqian Where exactly in the tutorial did you get that error?
we've had this reported several times but I haven't been able to reproduce the problem.
What has helped in the past:
dotnet --version
and output should be >= 2.1.300@seancpeters we've seen this error a few times.
@xsqian can you try the following:
dotnet new webapp -o ContosoUniversity
cd ContosoUniversity
dotnet run
using System;
using System.Collections.Generic;
namespace ContosoUniversity.Models
{
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
}
}
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 2.1.0
dotnet aspnet-codegenerator razorpage -m Student -dc ContosoUniversity.Models.SchoolContext -udl -outDir Pages\Students --referenceScriptLibraries
dotnet ef migrations add Initial
dotnet ef database update
Test the app. Navigate to /Students
I receive this same exact error when performing the "Create a Controller" step: https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db#create-a-controller
After performing these steps: Right-clicking on the controller folder Selecting the MVC Controller with views, using Entity Framework option Selecting the model class and Data context class After clicking the "Add" button, the above-mentioned error is produced.
@yamazaroon can you try the steps I've outlined above - starting with dotnet new webapp -o ContosoUniversity
I met this problem today,and I changed the version of Microsoft.AspNetCore.All in .csproj file then it worked in asp.net core2.1.
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
</ItemGroup>
@zackshine using M.A.All is discouraged. See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage?view=aspnetcore-2.1
I encountered the same error at the Create a Controller step (see @yamazaroon 's comment above) and tried the steps @Rick-Anderson suggested:
None of these solved the issue, so I deleted the project and re-ran this tutorial using ASP.NET Core Templates 2.1 instead of ASP.NET Core Templates 2.0 as directed in the Create a new project section. With this change I was able to complete the tutorial successfully and add new URLs to the Blog table.
I encountered the same problem as @xsqian reported. I resolved it as suggested by @dbiehle: .Net Core version, repair VS2017, start the project as .Net Core 2.1.
I was unable to install the Nuget packages per the tutorial, it seems I had 2.1.1 and .NC wanted 2.1.0. So I manually adjusted my.csproj thus:
I was then able to get past the previous error.
One thing I note: in the tutorial, immediately after clicking "Add Controller", it says... Select Full Dependencies and click Add You can ignore the instructions in the ScaffoldingReadMe.txt file that opens
I don't now what that's about, I got no option to do that, I went straight from clicking "add controller" to "Select MVC Controller with views, using Entity Framework and click Ok". There was nowhere to select "full dependencies" in between. Not sure if this helps...
The comment system my csproj as html. Here it is with the angle brackets converted to curly braces... {Project Sdk="Microsoft.NET.Sdk.Web"}
{PropertyGroup} {TargetFramework}netcoreapp2.1{/TargetFramework} {/PropertyGroup}
{ItemGroup} {PackageReference Include="Microsoft.AspNetCore.App" /} {PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" /} {PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" /} {PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" /} {/ItemGroup}
{/Project}
@joelbenford add version to M.A.App
{PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" /}
but 2.1.1
Closing. You get this error when you don't have the current .NET Core SDK installed.
There was an error running the selected code generator: ‘There was an error running the template C:\User\xsqian.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\2.1.1\Templates\ControlerGenerator\MvcControllerWithContext.cshtml: Template Processing Failed:(4,47): error CS0234: The type of namespace name ‘Hosting’ does not exist in the namespace ‘Microsoft.AspNetCore.Razor’ (are you missing an assembly reference?) (20,41): error CS0234: The type or namespace name ‘Hosting’ does not exist in the namespace ‘Microsoft.AspNetCore.Razor’ (are you missing an assembly reference?)’
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.