Opening Orchard in vs2012

Topics: Troubleshooting
Jul 11, 2012 at 4:02 PM

Hi,

I am trying to open the Orchard solution in newly installed Visual Studio Express 2012 RC. So far, I've had issues that for some reason VS2012 doesn't know that the projects are MVC projects, so it won't add Views/Controllers. Got past this by adding the following GUID to the .csproj file of each project in the solution:

{E53F8FEA-EAE0-44A6-8774-FFD645390401}

However, when I open a razor view, it shows these errors (among other related ones):

Error    20    The name 'model' does not exist in the current context    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    2    2    EventManagement

Error    21    The name 'T' does not exist in the current context    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    5    14    EventManagement

Error    22    'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor' and no extension method 'LabelFor' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)    c:\Users\willem\Documents\Visual Studio 2010\Projects\000-Orchard Development\src\Orchard.Web\Modules\EventManagement\Views\EditorTemplates\Parts\Event.cshtml    6    11    EventManagement

Also, Intellisense seems to be working in the razor view, but it only gives limited amount of fields for the Html helper method. For instance, none of the model specific methods like LabelFor and TextboxFor.

Not sure if this is Orchard specific, but thought you may have come accross it already? Any help is appreciated.

Thanks

Coordinator
Jul 11, 2012 at 5:59 PM

What version of Orchard is that?

Jul 11, 2012 at 11:16 PM

I downloaded the source zip of Version 1.4.2 from codeplex.

Jul 12, 2012 at 9:46 AM
Edited Jul 12, 2012 at 10:18 AM

I also realise now that when I open the orchard solution in VS2010 again it also gives the same issues! It definately worked in VS2010 before I installed VS2012.

So:

  • Opening an existing MVC3 project in either version gives the above errors in intellisense but NOT at runtime. It works fine at runtime.
  • When I add a new MVC3 project in 2010, I can open it in both versions and it works fine.
  • When I add a new MVC3 project in 2012 however, it works fine in 2012, but the project is unavailable in 2010 (incompatible with current version)
Jul 12, 2012 at 10:38 AM

I think that the issue is that the view doesn't have access to the referenced libraries in the root config:


  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="System.Linq"/>
        <add namespace="System.Collections.Generic"/>
        <add namespace="Orchard.Mvc.Html"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>

 

It does at runtime, but the intellilsense and error console doesn't pick it up

Coordinator
Jul 12, 2012 at 6:27 PM

Ah well, yes, that's by design. The solution can't depend on a specific version of MVC being installed on the machine.

Jul 12, 2012 at 11:03 PM

Hi Bertrand, thanks for the reply. I'm not sure I follow? I have now tested on three different machines, one of which never had VS2012 installed, and it still happens (even in Visual Web Developer Express 2010). Is there a solution to it?

Coordinator
Jul 12, 2012 at 11:30 PM

The version of VS doesn't matter. There isn't a solution because we must be able to load the solution even if MVC was not previously installed on the machine. But it works at runtime, right?

Jul 13, 2012 at 9:09 AM

It did on one of the machines, but on two of them it throws compiler errors. The only way I've been able to fix it was to uninstall MVC4. That seems to fix all the problems. It's a bit annoying since I would like to get started developing in MVC4, but at least all my Orchard solutions are now compiling.

Coordinator
Jul 13, 2012 at 11:03 AM

Well, MVC 4 is not out yet. It is often recommended to use VMs with beta software.

Coordinator
Jul 13, 2012 at 4:12 PM

You could fix this by modifying the binding redirect section in the web.config on Orchard.Web. Use a range like 0.0.0.0-4.0.0.0 => 3.0.0.0