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
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
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.
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.
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.
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).
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
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
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
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
Some of the errors I got after including the Models folder:
Any idea?
Hi Bilal
In you web.config have you got ?
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
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?
Hi,
I just tried the following and it works for me and I can have intellisense.
Umbraco.ModelsBuilder.ModelsMode
Make sure it reads something like:
Keep the Models folder excluded from the solution
Run the application and go to
/umbraco
admin areaVisit the
Developer
section. Then go toModels Builder
and click onReload
button.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
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.
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
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).
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
is working on a reply...