简体   繁体   English

ASP Core中_Layout.cshtml上的多个错误

[英]Multiple errors on _Layout.cshtml in ASP Core

I have an ASP Core application. 我有一个ASP核心应用程序。 It builds and runs without any problems but Visual Studio is showing lots of errors: 它构建和运行没有任何问题,但Visual Studio显示了很多错误:

| Severity  |  Code    |  Description                                                                                                                   |    Project File                  |
|-----------|----------|--------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| Error     |  CS0234  |  The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)           |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'Helpers' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)    |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)   |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)   |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0234  |  The type or namespace name 'WebPages' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)   |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0115  |  '_Page_Views_Shared__Layout_cshtml.Execute()': no suitable method found to override                                           |    1_Views_Shared__Layout.cshtml | 
| Error     |  CS0103  |  The name 'Context' does not exist in the current context                                                                      |    1_Views_Shared__Layout.cshtml |
| Error     |  CS0103  |  The name 'ViewData' does not exist in the current context                                                                     |    1_Views_Shared__Layout.cshtml |

The _Layout.cshtml file is the default one: _Layout.cshtml文件是默认文件:

<!DOCTYPE html>

<html>
<head>
    <title>BanksySan @ViewData["Title"]</title>
</head>
<body>
<div>

</div>
</body>

The only think different about this project is that it's been built up from a console application, rather than via the web template. 唯一的思考这个项目不同的是,它已经从一个控制台应用程序建立起来的,而不是通过网页模板。

I have the following package references: 我有以下包参考:

<ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
   <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="1.1.3" />
   <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" />
   <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
   <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
   <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="1.1.1" />
   <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
   <PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
   <PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
   <PackageReference Include="xunit" Version="2.2.0" />
</ItemGroup>

This to me is usually the case when Visual Studio was not able to load the basic require package such as system 当Visual Studio无法加载基本需求包(如system时,通常会出现这种情况

A) try to clean do a dotnet restore on the project folder B) if that didn't work clean nuget cache folder and run again C) Close visual studio and reboot and clean again. A)尝试清理项目文件夹上的dotnet restore B)如果不能正常工作清理nuget缓存文件夹并再次运行C)关闭visual studio并重新启动并再次清理。 it is also possible you have a zombie process that is still running that is not allowing visual studio to to access its temporary folder. 你也可能有一个仍在运行的僵尸进程,它不允许visual studio访问它的临时文件夹。 D) copy project to new path (git clone if possible) and to a fresh dotnet restore D)将项目复制到新路径(如果可能的话,将git克隆)复制到新的dotnet restore

I even had this error in Ride and above four helped me to get rid of it. 我甚至在Ride中遇到了这个错误,四个以上帮我摆脱了它。

I hope it helps Cheers 我希望它有助于干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM