question

SampathLokuge-6864 avatar image
0 Votes"
SampathLokuge-6864 asked DuaneArnold-0443 edited

No Controllers menu item on the Asp.net core 5.0 Web API project

Hi,

Microsoft Visual Studio Community 2019 Version 16.9.4 Windows 10 Pro

Any clue why I cannot see the Controllers menu item? This is the Asp.net core 5.0 Web API project

MS Doc says this: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-5.0&tabs=visual-studio#scaffold-a-controller

But I cannot see that?

Stackoverflow: https://stackoverflow.com/questions/67201201/no-controllers-menu-item-on-the-asp-net-core-5-0-web-api-project

CinamaApi.csproj

 <Project Sdk="Microsoft.NET.Sdk.Web">
    
   <PropertyGroup>
     <TargetFramework>net5.0</TargetFramework>
   </PropertyGroup>
    
   <ItemGroup>
     <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
   </ItemGroup>
    
   <ItemGroup>
     <Folder Include="Controllers\" />
   </ItemGroup>
    
 </Project>

90333-2.png

90334-3.png





dotnet-csharp
2.png (32.6 KiB)
3.png (35.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
1 Vote"
cooldadtx answered SampathLokuge-6864 commented

Hmm. It seems like the project file is correct but the IDE isn't synced properly with it. Have you restarted VS to ensure the solution view is synced? Things that can also get in the way include being in "folder view" in Solution Explorer and not having the solution actually open. If you can debug the project then that is not the case here.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @cooldadtx

Have you restarted VS to ensure the solution view is synced?

Yes and restart my PC too :D

Things that can also get in the way include being in "folder view" in Solution Explorer and not having the solution actually open. If you can debug the project then that is not the case here.

Sorry, I didn't get this. I have opened the Solution. You can see that on my images above too. Please see here too: https://stackoverflow.com/questions/67201201/no-controllers-menu-item-on-the-asp-net-core-5-0-web-api-project

Any clue? Why that Web API project has a C# class library icon?







0 Votes 0 ·

Stupid question but did you actually install the ASP.NET workload when you installed VS?

The reason I ask is that your project file seems like it is set up for ASP.NET but the view in solution explorer looks like you just created a regular console or class library project and then edited the project file to include the ASP.NET features. Therefore you don't have any of the ASP.NET tooling available. Your screenshot of the Add New Item UI also doesn't have the ASP.NET/Web category where all the ASP.NET-specific templates reside.

While you can manually create and build an ASP.NET project without the tooling, because ultimately the SDK is handling the details, you wouldn't be able to run nor would you have any of the editor features.

1 Vote 1 ·

Yes, you're correct. I didn't do that. I have just upgraded to the latest version through VS Installer. I have not used C#/Web APIs for many years due to the full focus on mobile apps. Since I have some free time now I have decided to refresh my knowledge again with Web APIs. Thanks a lot!

0 Votes 0 ·
DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered DuaneArnold-0443 edited

Of course one knows that .NET 5 is .NET Core. So you would have had to select a .NET Core Web project in order to get things to show correctly in the VS IDE using .NET 5.

Also, if adding a new controller, one would right-click on the Controller folder, Add new Item and Controller would be the first item that one can select above 'New Item' menu item without having to go into selecting an item in the list of items that are selectable for the project.

Maybe, you're not using a Core project, but somehow, you have selected .NET 5 that is .NET Core?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.