3
votes

I've created an empty ASP.NET Core Mvc project in visual studio for Mac, added a few dependencies

  • Microsoft.AspNetCore.Mvc (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

public class HomeController : Controller

I get a red squiggle line and an error:

the type of namespace name 'Controller' could not be found".

Also, I can't seem to find the project.json and csproj files in my project.

enter image description here

2
Did you install the .NET Core sdk? microsoft.com/net/core#macosMaria Ines Parnisari
Yes, because when I create a project from a template I don't get any errors. I only get an error when I create an empty projectInaloz_H

2 Answers

0
votes

You need to reference Microsoft.AspNetCore as well. This package contains references to a number of other packages that you need to build ASP.NET Core applications.

Try this working csproj file:

<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.json has been deprecated, so you won't see it in your project.

You do have a .csproj file, though. Visual Studio for Mac is representing it as the LanguageFeatures element in the tree view. You should also be able to see it if you ls in your current directory.

0
votes

So I finally solved this by removing and reinstalling Microsoft.AspNetCore.Mvc then I rebuilt the project.