Razor IntelliSense gone for Orchard members in VS 2013

Topics: Troubleshooting
Developer
Nov 13, 2013 at 1:12 PM
I.e. T(), delegate-based helpers and so on is underlined with red in templates in VS 2013. Has anybody else experienced this?

VS 2012 needs ASP.NET MVC 3 tooling installed for IntelliSense to work but it doesn't help for 2013 (tried MVC 4 too, doesn't help either).
Nov 13, 2013 at 2:48 PM
I'm also interested in this.
Nov 13, 2013 at 7:09 PM
Already mentioned in issues and ... closed....
https://orchard.codeplex.com/workitem/20259
Coordinator
Nov 13, 2013 at 7:17 PM
re-opened
Nov 13, 2013 at 8:05 PM
Have you codeplex directly connected in your brain ?
Developer
Nov 13, 2013 at 8:45 PM
FYI this happens in any solution I tried, including the main Orchard source too, with templates in modules as well as ones in Core. I searched for similar issues but couldn't find a suitable resolution. Web.configs seem fine and there shouldn't be any issue with tooling. The same solutions work perfectly fine in VS 2012.
Nov 13, 2013 at 10:28 PM
And I also get 'The name model does not exist in the current context' on
@model dynamic
Developer
Nov 13, 2013 at 10:32 PM
I managed to fix this a while back - for some reason the <assembly> references to the MVC assemblies need to be in the root Web.config of a module for this to work. They are missing from all modules I've checked, and also from the result of generating a new module project.

Root Web.config of a module should look like this:
    <appSettings>
        <add key="webpages:Version" value="2.0.0.0"/>
        <add key="webpages:Enabled" value="false"/>
        <add key="PreserveLoginUrl" value="true"/>
        <add key="ClientValidationEnabled" value="true"/>
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    </appSettings>

    <system.web>
        <compilation targetFramework="4.0">
            <assemblies>
                <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
                <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
            </assemblies>
        </compilation>
        <pages controlRenderingCompatibilityVersion="4.0">
            <namespaces>
                <add namespace="System.Web.Helpers"/>
                <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"/>
            </namespaces>
        </pages>
    </system.web>
    
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
View/Web.config should like like this:
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.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="Orchard.Mvc.Html"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>
After making my Web.config files look like the above, all Razor view realtime compilation and IntelliSense start working again in VS2013 for me.
Nov 13, 2013 at 10:50 PM
Edited Nov 13, 2013 at 10:51 PM
Nice work changing all this... :(
Do you know the usage of
<appSettings>
        <add key="webpages:Version" value="2.0.0.0"/>
        <add key="webpages:Enabled" value="false"/>
        <add key="PreserveLoginUrl" value="true"/>
        <add key="ClientValidationEnabled" value="true"/>
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    </appSettings>
Developer
Nov 14, 2013 at 4:50 PM
Thanks Daniel this indeed solves the issue. However I hope there is a simpler way or we really have to modify all the modules.
Developer
Nov 14, 2013 at 4:53 PM
I think we need to, and should update all modules. The current Web.config files are a little outdated and messy, with some redundant things specified in the wrong places. But I think Erik Oppedijk has done a lot of Web.config cleanup in the fw45 branch - maybe he's already fixed this there?
Nov 14, 2013 at 5:50 PM
Edited Nov 14, 2013 at 5:52 PM
I will try because, as I was already runnng in 4.5, I had changed all the web.config to have the same version for all assemblies concerning razor, idem for mvc and webpages, getting this from google....but when I moved to VS2013, intellisense was broken.
I would say that lot of modules have very disparate web.config and as I was not knowing the reason why they had not evoved, I kept the differences, only upgrading the assemblies mentionned previously.
I have already raised this point in the past but the answer I got from Bertrand was that Web.config was not used when building and running, which seems quite true.
But for editing it seems that it's necessary to have a coherent hierarchy.
I have seen that Erik has set everything for MVC 5 in what was 4.5 and is now 1.x or is it Owin (?)
Developer
Nov 14, 2013 at 6:12 PM
I think it's only partly true that the Web.config files aren't used at runtime. I think any Razor views in a module are actually rendered within the context of their physical location, so when rendering the views I think the module Web.config files are actually in effect. I asked Sebastien to verify if this was true, and he said he believed the same.

I'll have a look at 1.x and see if something additional needs to be done in the Web.configs or if Erik's changes are sufficient.
Nov 14, 2013 at 7:44 PM
Just have a look on the conclusions here
https://orchard.codeplex.com/discussions/442338
but the orchard building process being no more dynamical with source files monitoring ???
Developer
Nov 14, 2013 at 8:06 PM
Yes, exactly what Bertrand says:
The ones in views, scripts, content, and styles should matter [at runtime], but not the one in the root.
The one in the root is only there for the editing experience at design time.
Nov 16, 2013 at 6:51 PM
I think sebastian broke the intellisense ;)

I upgraded everything to MVC 4, Sebastian only upgraded the root project to MVC 5, with the assembly binding redirects.

All modules now have an MVC 5 DLL, but they still have 4.0 web.config files.

The solution (I will create a patch for 1.x) is to update all web.configs to reference the right version.

Also the views/web.config shouldn't be updated, I think they can completely go.
The module web.config could use this:
  <appSettings>
    <add key="webpages:Enabled" value="false"/>
    <add key="webpages:Version" value="3.0.0.0"/>
  </appSettings>
Nov 17, 2013 at 8:52 AM
Edited Nov 17, 2013 at 8:54 AM
I finally get it working with the model of a fresh VS2013 mvc project, but I used .Mvc 5, .WebPages, WebHelpers and related 3, Razor 3, adding as Erik said the <add key="webpages:Version" value="3.0.0.0"/> where it was missing (what is the usage ?).
But the key point is that the assemblies in lib\aspnetmvc are respectivelly versions 4, 2 and 2, so I copied the mvc package lib contents for these assemblies and udated the project files.
Doing this I discovered that there are very strange lines in some of them, binding forced to mvc version 3, webpages 1, etc. Lot of cleaning necessary there.
Intellisense ok now and code running with mvc5.
I also noted that Owin is native now for any vs2013 mvcproject...and bootstrap 3.0

Hoping now the migration will be soon, could we go on 4.51 the better.
Nov 17, 2013 at 10:32 AM
The appsettings with the webpages:enabled isn't necessary I found out, you can leave them from the modules. The top level already has these settings.

Webpages:enabled=false makes sure a cshtml view isn't rendered when requested by a direct URL, but this setting seems useless everywhere
Nov 18, 2013 at 7:35 AM
And do you know the usage of the .dll.config files generated by compiler for each module assembly ?
I noticed they are also incuded in the published set ?
Developer
Nov 23, 2013 at 8:11 PM
Edited Nov 23, 2013 at 9:08 PM
Hmm, it seems that the latest source, although including the updated Web.configs (that also have increased version numbers for the assemblies too), doesn't work. Razor is broken in VS 2013 and furthermore also in 2012. While in 2013 expressions are shown as errors (e.g. "Error The type arguments for method 'Orchard.Mvc.Html.HtmlHelperExtensions.FieldIdFor<T,TResult>(System.Web.Mvc.HtmlHelper<T>, System.Linq.Expressions.Expression<System.Func<T,TResult>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly." for Html helpers) in 2012 Razor InstelliSense is totally missing (while in the latter there's no issue with modules with the old Web.configs).
Nov 24, 2013 at 7:50 AM
That's the source of the problem, only the root project was updated to MVC 5, but not all config files.

My pull request is still waiting, in there, all the modules are updated as well.

I also cleaned up all the web.configs from the views folder, they are not needed anymore.
Developer
Nov 24, 2013 at 9:59 AM
Taken a look at the pull request, seems great!