[英]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 项目,添加了一些依赖项
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.json
和csproj
文件。
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
andcsproj
files in my project.此外,我似乎无法在我的项目中找到project.json
和csproj
文件。
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.