简体   繁体   English

ASP.NET Core MVC 中缺少类型/命名空间

[英]Missing type/namespace in ASP.NET Core MVC

I've created an empty ASP.NET Core Mvc project in visual studio for Mac, added a few dependencies我在 Visual Studio for Mac 中创建了一个空的 ASP.NET Core Mvc 项目,添加了一些依赖项

  • Microsoft.AspNetCore.Mvc (1.1.2) Microsoft.AspNetCore.Mvc (1.1.2)
  • Microsoft.AspNetCore.Mvc.Core (1.1.2) Microsoft.AspNetCore.Mvc.Core (1.1.2)

and also imported the namespaces.并导入了命名空间。 However, when I create a new HomeController class and try to inherit from the Controller class但是,当我创建一个新的HomeController类并尝试从Controller类继承时

public class HomeController : Controller

I get a red squiggle line and an error:我得到一条红色波浪线和一个错误:

the type of namespace name 'Controller' could not be found".找不到命名空间名称“Controller”的类型”。

Also, I can't seem to find the project.json and csproj files in my project.此外,我似乎无法在我的项目中找到project.jsoncsproj文件。

在此处输入图片说明

You need to reference Microsoft.AspNetCore as well.您还需要引用Microsoft.AspNetCore This package contains references to a number of other packages that you need to build ASP.NET Core applications.此包包含对构建 ASP.NET Core 应用程序所需的许多其他包的引用。

Try this working csproj file:试试这个有效的 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
  </ItemGroup>

</Project>

Also, I can't seem to find the project.json and csproj files in my project.此外,我似乎无法在我的项目中找到project.jsoncsproj文件。

project.json has been deprecated , so you won't see it in your project. project.json 已被弃用,因此您不会在您的项目中看到它。

You do have a .csproj file, though.不过,您确实有一个 .csproj 文件。 Visual Studio for Mac is representing it as the LanguageFeatures element in the tree view. Visual Studio for Mac 将其表示为树视图中的 LanguageFeatures 元素。 You should also be able to see it if you ls in your current directory.如果您ls在当前目录中,您也应该能够看到它。

所以我最终通过删除并重新安装 Microsoft.AspNetCore.Mvc 解决了这个问题,然后我重建了项目。

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

相关问题 &#39;找不到类型或名称空间名称&#39;BookModel&#39;ASP.NET MVC - 'The type or namespace name 'BookModel' could not be found ASP.NET MVC 在 asp.net core 2.2 中找不到类型或命名空间名称“Worker”(您是否缺少 using 指令或程序集引用?)? - The type or namespace name 'Worker' could not be found (are you missing a using directive or an assembly reference?) in asp.net core 2.2? ASP.Net Core MVC缺少程序集参考 - ASP.Net Core MVC missing assembly reference 带有 Blazor 的 ASP.NET Core 3.1 MVC - 缺少程序集 - ASP.NET Core 3.1 MVC with Blazor - Missing Assembly ASP.NET 核心 2 - 缺少内容类型边界 - ASP.NET Core 2 - Missing content-type boundary ASP.NET Core 3.0:命名空间中不存在类型或命名空间名称“CreateDefaultBuilder” - ASP.NET Core 3.0: The type or namespace name 'CreateDefaultBuilder' does not exist in the namespace ASP.NET添加类和命名空间丢失 - ASP.NET Add class and namespace missing 在 ASP.NET MVC 中为 JSON 引用命名空间 - referencing namespace for JSON in ASP.NET MVC ASP.NET - 类型或命名空间不存在 - ASP.NET - type or namespace does not exist 在 ASP.NET Core MVC Razor 视图中,与@model IEnumerable 相关的问题<namespace.model>对比@model<namespace.model></namespace.model></namespace.model> - In an ASP.NET Core MVC Razor view, issue related to @model IEnumerable<Namespace.Model> Vs @model<Namespace.Model>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM