MVC3 Project Template Requires Solution Node in Solution Explorer

I've got Visual Studio 2010, MVC3, and the latest tools update. I'm all patched up. But I'm seeing something weird.

I start out and I have a solution with a single C# class library in it.

Solution with one class library.

I decide to add an MVC3 site to it, so I do File -> Add New Project. I select an MVC3 project.

Add new ASP.NET MVC3 Web Application

I click OK, and I select an Empty web application.

Selecting an empty MVC3 project.

When I click OK on this screen, I get an error "Cannot add the item because the item to add it to is not a solution folder or the solution."

Error: Cannot add the item because the item to add it to is not a solution folder or the solution.

I click OK to dismiss the error and I see there's a folder in the filesystem named the same as the project name I selected (like it started to put the project in there) but the folder is empty.

To work around this, you have to:

  1. Add a second project to your solution so that the solution itself shows up in Solution Explorer.
  2. Select the Solution node in Solution Explorer by clicking it once. It can't be one of the projects. It has to be the solution.
  3. Now do File -> Add New Project and go through the steps to add the Empty ASP.NET MVC3 web application and it will work.

I'm not sure what's going on where the project template is somehow keyed to the solution, but there you go.

posted on Friday, October 28, 2011 2:31 PM | Filed Under [ Web Development .NET Visual Studio ]

Comments

Gravatar # re: MVC3 Project Template Requires Solution Node in Solution Explorer
by Dario at 10/30/2011 9:33 PM
Another work around is to get Visual Studio to show a solution (by default the solution is hidden in the Solution Explorer pane for solutions with only a single project).

To always show the solution hierarchy go to Tools --> Options --> Projects and Solutions and check the option "Always show solution".

I actually dislike the default setting here and I've seen it cause a lot of confusion.
Gravatar # re: MVC3 Project Template Requires Solution Node in Solution Explorer
by Travis Illig at 10/31/2011 8:18 AM
Excellent tip! I didn't even know that setting existed. I'd still call it a defect in the project template, but this might be a simpler workaround.
Comments have been closed on this topic.