This project is read-only.

Can't Create Razor Views in VS 2010

Topics: Troubleshooting
Mar 6, 2011 at 4:08 PM

I've recently installed Orchard and I'm having some difficulty with creating a new module.

I've followed the instructions in the documentation to create the hello world module. I've got the module created and it's being recognized by the CMS in the dashboard. However, when I try to add a view in VS 2010 I don't see the option to add a View, and cshtml is an option under the normal Add Item menu.

I created a new MVC3 project to ensure that MVC 3 is installed properly, and I can add views just fine in the newly created project.

Any ideas why the code generated module isn't being recognized as a MVC app? As an alternative, is there an outline on how to create a module without the code generation module?

Mar 6, 2011 at 5:41 PM

Just a note, if I download the sample code for the HelloWorld module, it works fine. This leads me to believe there might be something up with the CodeGeneration module.

Mar 8, 2011 at 2:40 AM

If it helps, I've included a copy of HelloWorld module created with the Codegen module and Bertrand's sample side by side. I compared the 2 using WinMerge and there are definitely some differences between the 2


The problem appears to be in the HelloWorld.csproj file. If I copy the project file from the sample into my code generated version, the proper MVC options come up in the right click menu for the Views folder and the Controllers folder.

Mar 8, 2011 at 4:20 AM
Edited Mar 8, 2011 at 4:22 AM

This is unfortunately "by design". To be recognized as an MVC project (and hence have the "Add View" menu item), the .csproj needs to contain the MVC project type GUID. The problem with Visual Studio is that, if MVC tooling is not installed on the machine when you open these .csproj files, Visual Studio will not be able to open these projects properly.  The error message is pretty obscure (VS complain about a project GUID not installed, nothing about MVC tooling missing), and we received quite a few complains about this.

So, we had to decide between removing support for "Add View" when tooling is installed, or inabilty to open the project when tooling is not installed. We chose the later, as we wanted the source project to open "out of the box" with any standard VS2010 installation.

The workaround in your case is to add the MVC3 project type GUID in the .csproj file.

Mar 8, 2011 at 6:41 AM

Thanks, I have the guid entered and the Add View option is now available. However, it appears that I can only create views, not razor views. When I try to use a view with a cshtml extension, it throws an exception saying that the view was not found or no view engine supports the searched locations. In the list of locations, it is looking in the folder that contains my views, but is only looking for aspx and ascx extensions.

Is there an additional step I need to take to enable the Razor view engine?

I apologize if these questions have been answered before, but I couldn't find them via the search.

Nov 21, 2011 at 11:44 AM

It worked for me, with this work around.
I added a new MVC web-app to the modules folder (in the source code via VS 2010). I used code-gen to create another test-module and then copied the Module.txt file (and a few other relevant files, though I feel copying Module.txt is sufficient) to this manually created MVC web-app. Note that the 'name' in Module.txt needs to be updated in the MVC app after copying the file there. I'm still testing this and so far it is working for me. I had to get Razor in my app..
Orchard experts, please correct me on this if required. Hopefully this should help someone ahead!