Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dean 13 posts 56 karma points
    May 01, 2015 @ 20:10
    Dean
    1

    Visual Studio IntelliSense issue with latest version(s) of Umbraco

    I am having issues with Visual Studio IntelliSense being unable to recognise Layout, ViewBag etc. on version 7.2.2.

    This is occuring on a build which is in progress.

    To check if the solution has been broken during development I tested using a vanilla Umbraco install.

    I created a new Visual Studio solution and project and included files from the 7.2.2 installation .ZIP. I referenced all package DLLs and built successfully. I then added a layout and view and IntelliSense is failing.

    I performed the same test with 7.2.4 and observed the same results.

    I am hoping this is something simple, any help would be appreciated.

    Thanks,

    Dean

     

     

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    May 01, 2015 @ 21:03
    Anders Bjerner
    1

    Hi Dean,

    Can you elaborate a bit further on how you installed Umbraco? I just tried downloading the ZIP for Umbraco 7.2.4, unzipped the file, and created a Visual Studio project in the same folder, and it worked fine.

    The thing is however - you must first add the .cshtml files to the project file (see screenshot).

    Screenshot

    Visual Studio will offer me intellisense for Hest.cshtml, but not for Test.cshtml since that file hasn't yet been added to the project.

    Does this solve your issue? If it doesn't help - or you already have added the files - would you be able to upload a ZIP of your solution?

  • Dean 13 posts 56 karma points
    May 04, 2015 @ 11:53
    Dean
    0

    Thanks for the reply Anders.

    I have found the solution, as expected it was something simple!

    I configured my test project as follows:

    • Create an empty solution and web application project.
    • Copy all files from the installation ZIP into the project directory.
    • Include all files into the solution (excluding bin and obj folders).
    • Move all assemblies out of the bin folder into an external references folder.
    • Add references to all assemblies via Visual Studio.
    • Create layout page and view page CSHTML files.
    • Successfully build the application.
    • Observe that DLLs have been copied back into the bin folder.

    At this point, IntelliSense was not working on my views.

    I added the following to the top of my layout page: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    This worked fine, Visual Studio recognised the UmbracoTemplatePage class which is present as part of umbraco.dll.

    Viewing the class definition (F12) I could see that UmbracoTemplatePage's base class, UmbracoViewPage, was also successfully recognised.

    I continued through the inheritance path (both WebViewPageand WebViewPage were recognised) and found that System.Web.WebPages.WebPageBase was unrecognised.

    I then noticed the problem:

    I had moved all content from the bin folder into an external references folder, when adding the contents back into the project as external references it looks as though Visual Studio configured most as copy local = true, however some .NET Framework references were set to copy local = false.

    Although the application built successfully, the necessary assemblies were not being pulled into the bin folder and therefore IntelliSense was not working.

    It seems odd that Visual Studio defaults copy local = false for framework assemblies if it breaks IntelliSense. On a more fundemental level, it seems strange that IntelliSense is driven by the content of the bin folder if some references will be never copied into the directory.

    Hope this helps someone.

    Thanks,

    Dean

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    May 04, 2015 @ 17:05
    Sebastiaan Janssen
    0

    Just as a tip: what it sounds like you're doing is moving files out so they won't be under source control. This is exactly why NuGet was created and it will manage all this automatically for you without you having to suffer through problems like this.

    I also think that you might need to check the web.config file in the Views folder, make sure that it's included in the Visual Studio project and contains the following namespaces (then you shouldn't have to update your @inherits either):

      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.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="Umbraco.Web" />
            <add namespace="Umbraco.Core" />
            <add namespace="Umbraco.Core.Models" />
            <add namespace="Umbraco.Web.Mvc" />
            <add namespace="umbraco" />
            <add namespace="Examine" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    
  • Dean 13 posts 56 karma points
    May 04, 2015 @ 23:18
    Dean
    0

    Hi Sebastiaan,

    I have created a new test app and used NuGet to add Umbraco as a reference; I can see that when using NuGet the System.Web.WebPages reference is automatically set to copy local = true. Great! That fixes the IntelliSense problem.

    I have also noticed that only the Config and Views directories are automatically included within the solution which is perfect when using publish profiles to frequently deploy lightweight payloads to a separate local web-root.

    I think it makes sense to move the project over to NuGet. I have so far been skeptical of using Umbraco via NuGet on client builds, I have been unsure how smooth the upgrade process would work in the real world (against builds that include substantial extensions and cusomisations, additional third party references etc.).

    The NuGet upgrade instructions do not appear overly complicated (https://our.umbraco.org/documentation/installation/upgrading/general), however one line throws up some questions:

    "Or you can open the NuGet Package Manager and select the Updates pane to get a list of available updates. Choose the package called UmbracoCms and click update. This will run through all the files and make sure you have the latest changes while leaving files you have updated."

    I'd be keen to be warned about such files (does the upgrade process log this detail?) to understand the potential impact of not keeping these in-line with the default install.

    Do you have any tips regarding the upgrade process via NuGet? Are you aware of any gotchas?

     

    RE the Views folder Web.config:

    The Web.config is included, but (as above in your example) it references System.Web.Mvc.WebViewPage as the pageBaseType. Adding @inherits Umbraco.Web.Mvc.UmbracoTemplatePage to my view allows me to access useful objects such as the current page (@CurrentPage), Umbraco helper (@Umbraco) and context (@UmbracoContext).

    Am I following the correct approach? Or should I access these objects using another method?

    Thanks for the help,

    Dean

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    May 08, 2015 @ 09:02
    Sebastiaan Janssen
    0

    NuGet is pretty smooth and if you have any doubts about it then you have everything in source control, right? So you can always revert any changes that were made through it. I never worry as I know I can always go back to a previous state.

    NuGet is designed to be safe and doesn't touch anything that it shouldn't.

    Other than that the NuGet instructions in the documentation contains all the "gotchas" you might run into. It's even slightly outdated, it talks about merging config files: when you upgrade through NuGet, we handle the merging of those files so it's almost completely automated now.

    Yes, templates user UmbracoTemplatePage, that's how Umbraco is meant to be used.

Please Sign in or register to post replies

Write your reply to:

Draft