Copied to clipboard

Flag this post as spam?

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


  • Bilal Haidar 144 posts 410 karma points
    Sep 16, 2016 @ 18:27
    Bilal Haidar
    0

    Intellisense with ModelsBuilder in Visual Studio

    Hi, I am using the latest release of Umbraco. I read that ModelsBuilder comes installed and configured by default.

    I can see that there is a new folder called Models that got generated inside the App_Data folder and that folder is excluded by default from the solution.

    If I want to make use of ModelsBuilder, I need to change how the Views inherit and make it something like

    UmbracoViewPage<NameOfGeneratedClassByModelsBuilder>
    

    However, Visual Studio seems not to see the Namespace created by ModelsBuilder neither I am getting intellisense when inside VS.

    Any help is appreciated.

    /Bilal

  • Marc Goodson 2126 posts 14218 karma points MVP 8x c-trib
    Sep 16, 2016 @ 22:34
    Marc Goodson
    0

    Hi Bilal

    Include the generated files in your Visual Studio (right click include in project) and then intellisense should be able to find them!

    and you can now use:

    @inherits UmbracoTemplatePage

    to define the generated model for your views, and maintain access to all the usual Umbraco helpers.

    regards

    Marc

  • Bilal Haidar 144 posts 410 karma points
    Sep 17, 2016 @ 06:07
    Bilal Haidar
    0

    Some of the errors I got after including the Models folder:

    CS0579  Duplicate 'AssemblyVersion' attribute   bumbraco    D:\...\Properties\AssemblyInfo.cs   34  Active
    
    CS0579  Duplicate 'System.Reflection.AssemblyVersion' attribute bumbraco    D:\...\App_Data\Models\models.generated.cs  23  Active
    
    CS0579  Duplicate 'PublishedContentModel' attribute bumbraco    D:\...\App_Data\Models\models.generated.cs  28  Active
    
    CS0102  The type 'Home' already contains a definition for 'ModelTypeAlias'  bumbraco    D:\...\App_Data\Models\models.generated.cs  32  Active
    
    CS0111  Type 'Home' already defines a member called 'GetModelPropertyType' with the same parameter types    bumbraco    D:\...\App_Data\Models\models.generated.cs  47  Active
    

    Any idea?

  • Marc Goodson 2126 posts 14218 karma points MVP 8x c-trib
    Sep 17, 2016 @ 09:23
    Marc Goodson
    0

    Hi Bilal

    In you web.config have you got ?

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
          <add key="Umbraco.ModelsBuilder.ModelsMode" value="AppData" />
    

    and have you at any point had the ModelsMode set to PureLive or Dll Models ? Wondering if there are two versions of your generated models (ie one in a dll, and another in your app_data folder, and since these are generated as Partial classes, they are being combined, hence the duplicate warnings.

    regards

    Marc

  • KD91 1 post 71 karma points
    Sep 22, 2016 @ 13:13
    KD91
    0

    I've got this exact same issue - brand new Umbraco install from NuGet. Only change to web.config is the connection string / debug mode.

    Added a few DocTypes / Templates.

    Include the App_Data files and I get intellisense but then it will no longer compile due to errors in the generated files.

    If I change the build-action on the files to None, it will compile as it should, but then I lose the intellisense again.

    Is the only method to do this to run it, then remove them from the project when you want to run a VS build?

  • Bilal Haidar 144 posts 410 karma points
    Sep 22, 2016 @ 15:09
    Bilal Haidar
    1

    Hi,

    I just tried the following and it works for me and I can have intellisense.

    1. In the Web.config, locate the appSettings named Umbraco.ModelsBuilder.ModelsMode
    2. Make sure it reads something like:

      <add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll"/>
      
    3. Keep the Models folder excluded from the solution

    4. Run the application and go to /umbraco admin area

    5. Visit the Developer section. Then go to Models Builder and click on Reload button.

    6. The above creates a new DLL in your bin folder Umbraco.Web.PublishedContentModels.dll

    Now, you've got intellisense in your solution.

    Hope this helps,

    /Bilal

  • Sotiris Filippidis 286 posts 1501 karma points
    Sep 22, 2016 @ 19:57
    Sotiris Filippidis
    0

    I've been using Dll mode too. The only caveat is that if you install Umbraco via Nuget, use source control (typically excluding binaries) and then clone your project from your source control in another computer you won't have the file Umbraco.Web.PublishedContentModels.dll available so, no models and additionally the whole installation will be crashing on launch because it will expect to find that dll.

    So you either have to include this Dll in your source control or - as I did in a couple of cases - switch to Appdata mode, temporarily copy generated classe sto the appcode folder, get Umbraco running, re-switch to Dll mode, generate your models, delete the generated classes from appcode and go. :) Not a very easy approach, but does the job in case you don't have the Dll any more.

  • Bilal Haidar 144 posts 410 karma points
    Sep 22, 2016 @ 20:18
    Bilal Haidar
    0

    You can always include specific dlls in your bin to be copied to production.

    In fact, the custom code I write usually resides in a separate DLL and hence I always need to include the dll in the project to get copied to production.

    /Bilal

  • Sotiris Filippidis 286 posts 1501 karma points
    Sep 23, 2016 @ 05:48
    Sotiris Filippidis
    0

    That's very true, yes. I wasn't talking about publishing to production, though. I was talking about cloning your nuget-installed site (via source control, e.g. Git) to another computer that has never ran it, restore nuget packages and get going - in this case, you clone the solution with all its projects, so any custom code will be there - and will be compiled into a dll if it's a separate project referenced by your main one.

    What will not be there, though, is the Umbraco.Web.PublishedContentModels.dll file since this is generated via Umbraco. It doesn't get generated on application start if it doesn't exist (or at least that's my experience so far). So if you use source control, you need to either add this libary to source control or do the ugly stuff I described above (unless there's an easier solution to that which I'm not aware of).

  • Marc Goodson 2126 posts 14218 karma points MVP 8x c-trib
    Sep 24, 2016 @ 09:31
    Marc Goodson
    0

    Just to be sure here

    By default, a fresh install runs modelsbuilder in PureLive models mode

    This needs to be changed to AppData mode to enable you to include the generated files in Visual Studio and gain intellisense.

    Dll mode is useful if you have multiple projects in your visual studio solution that need to interact with the generated models and you want to avoid circular references.

    The AppData mode is there to help you work with intellisense and Visual Studio and extend the models, so we need to create this as an issue if it is not working properly. The errors about duplication can occur if the same models have already been generated in dll mode, or are included in the solution but you're running in PureLive mode.

    But could equally be an issue with latest version of Umbraco

Please Sign in or register to post replies

Write your reply to:

Draft