Wednesday, January 8, 2014

Configuring an existing MVC project correctly.

Today I had a little problem when I tried to add a view to an existing controller. The project was built on TFS by some other. When I started working on that it didn't workout in the usual manner. I rightclicked on the  controllermethod hoping to add a view. But it was not there. :(

It is very easy to fix this. :) I follow the solution first theory. Guys, be happy. We'll discuss later. Just follow these steps and you are done. If you want to UNDERSTAND read further. :)

  1. Make an MVC4 Project in Visual Studio.Open Visual Studiowhat ever the version you have. New Project->Web->ASP.NET MVC4 WebApplication
 Then on the next popup just click any template. I selected Empty template.
Now you have created a new MVC project. Hell!!!! we don't need this. Just close it. :o

 2.  Open your project folder. ASP.NET or MVC project which doesn't work as usual. There is the .csproj file. Right click on it and open it with a text editor. I use notepad++.

  3.  There you can see an XML type file. Find the tag with the XML heading <ProjectTypeGuids>.

 That is what you need. 


In order to fix the problem we need to edit this tag. 

4. Go to that HELL project folder we created. Do the same in the step 2 and open the .csproj file in the text editor. Copy the respective part as follows.

 There maybe ONE or MANY keys in curly brackets as above. Doesn't matter. You need the first one only. Just copy and paste it in the place shown in step 3. That is to the problomatic .csproj file. Don't forget the semicolon at the end of curly brackets. Also you should copy it write infront of the list. Other words just after the <ProjectTypeGuids>.

Also when copying, you may be restricted to write this file. Then make sure you have deselected Read-Only option in properties. (Write click on the .csproj, <the image in step2>  and click properties. Then deselect the Read-Only option at bottom.)

So the edited .csproj will look like follow. (The same in step 3 after editing should looks like follow finally.)

Now save it man. Hola!!!! You are done. See, now I have the AddView, Go To view same as we do in a usual MVC project.

Let's dig in shortly what we have done.

No comments:

Post a Comment