11

I am using Visual studio 2015 and after opening an existing project, I am not able to see the add controller option while right clicking on the Controller Folder. Please help.

Sagnik Mukherjee
  • 163
  • 1
  • 1
  • 9

11 Answers11

10
  • Open VS2015=>TOOLS=>Customize
  • Select Commands
  • Select Context menu
  • Select Project and Solution Context Menus|Folder|Add
  • Check that 'Controller' appears.
  • IMPORTANT - Move up Controller item to the top.
Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
  • 3
    Following this made the Controller option appear for me but clicking the controller option doesn't actually do anything! – thudbutt Nov 26 '15 at 16:14
  • 3
    Same here, I now have the option to add a controller which is invisible, inaudible, tasteless and odourless. I tried reaching out with my feelings, but even the force couldn't detect it. I would have preferred a chocolate teapot. At least I could console myself with confectionery therapy. – GPR Dec 01 '15 at 16:17
  • 1
    I was under the impression these context options for **Controller** or **Views** appear depending on the NuGet packages you have installed in **project.json**, specifically Entity Framework packages in conjunction with the **Microsoft.Extensions.CodeGenerators.Mvc** package. I noticed this when building my project up from an empty template and then gradually adding packages I needed. At some point, the Controller and Views context menu items seemed to be made available. – Darren Evans Apr 02 '16 at 12:16
  • 1
    Just did a test from an Empty Project and it was only after adding the following packages to project.json that the Controller and View context menu items appeared: EntityFramework.Commands": "7.0.0-rc1-final", EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final" – Darren Evans Apr 02 '16 at 12:32
  • @thudbutt I'm having the same issue in VS 2017 - how did you fix it? – niico Apr 09 '17 at 18:56
  • @niico Afraid I didn't, I think I was using an RC version and I put it down to that. – thudbutt Apr 09 '17 at 19:00
  • @thudbutt thanks - doing a full re-install here (only did a complete machine wipe 2 weeks ago). – niico Apr 09 '17 at 21:27
6

I had the same problem on my ASP.NET project in VS2015. I solved by installing Microsoft.VisualStudio.Web.CodeGeneration.Tools. It doesn't appear in NuGet Manager so you have to install with Package Manager Console: Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Tools -Version 1.0.0-preview2-final -Pre

Hope it helps

Marc
  • 101
  • 2
  • 4
4

I had the same issue. After messing around with the GUID numbers and trying to reinstall, the answer came down to updating Visual Studio 2015.

Go to Tools > Extensions and Updates > Updates (Tab on the left) > Visual Studio.

It was around 3 Gigs.

Hope this helps

Dominic Cabral
  • 962
  • 9
  • 21
  • I had the issue and updated "github extension" in "Go to Tools > Extensions and Updates > Updates". After restarting VS2015, the add controller menu item was back. I guess updating any Extensions will do. – sunpochin Feb 07 '16 at 18:11
3

OK, this was driving me up the wall so I created a default MVC project to see what on earth I was missing, would you like to know?? Here is the answer.

In project.json under dependencies, please add:

"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final"

Or which ever version is now available. Then right click your folders for views etc and the menu options appear!

Monolithcode
  • 598
  • 8
  • 19
1

From [Chris Zhao on asp.net][1]: You could consider uninstalling VS 2015, and reinstall it again,and check whether "Web Developer tools" is selected [go into Custom during the installation to be sure it is checked.

I did this and it enabled the add controller option.

josliber
  • 43,891
  • 12
  • 98
  • 133
Reid
  • 3,170
  • 2
  • 23
  • 37
1

Right Click on Add Reference --> ManageNugetPackage --> Search for Microsoft ASPNET.MVC and Install that package. Then come back to project and right-click on controller folder and see ;-)

1

Use the following command in the NuGet console to install the package.

Install-Package Microsoft.Extensions.CodeGenerators.Mvc -Pre 

Good Luck.

DragoRaptor
  • 735
  • 5
  • 10
1

Adding the following 2 dependencies in project.json worked for me to get Add controller and view context menus as well as the scaffolding. I have VS 2015 with Update 3.

Under dependencies -

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
  "version": "1.0.0-preview2-final",
  "imports": [
    "portable-net45+win8"
  ]
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview2-final"

And under Tools section:

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
  "version": "1.0.0-preview2-final",
  "imports": [
    "portable-net45+win8"
  ]
}
Mayeed
  • 691
  • 1
  • 7
  • 19
0

If you have recently cleaned all the files in your solution then it may just be a matter of re-building the solution, to restore your NuGet packages.

MikeBeaton
  • 3,314
  • 4
  • 36
  • 45
0

I followed every step and nothing worked. so the problem is definitely related to the code generators, but what I had to do is include booth codeGenerator.MVC and CodeGeneration.Tools in the dependencies section

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
  "type": "build",
  "version": "1.0.0-preview2-final"
}

And the following in the tools section

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": "1.0.0-preview2-final"
enter code here

FYI: No need to follow the steps TOOLS=>Customize, once the code generator is added the Controller will appear immediately.

SaadK
  • 1,507
  • 20
  • 33
0

I had the same problem. I closed and re-opened Visual Studio and then the issue solved.

Mohsen
  • 971
  • 2
  • 11
  • 29