Published Models not found - Umbraco 9 on .NET Core
Hey everyone.
I'm attempting to build out a simple site on Umbraco 9 and .NET Core, mainly for testing purposes.
However, PublishedModels is behaving odd. I see the generated models under ~/umbraco/models/, but the razor views do not recognize PublishedModels.XXXX (i.e. @inherits UmbracoViewpage
Does anyone know what I might be doing wrong? Or where in appsettings to change modelbuilder mode since I don't have web.config?
I'd appreciate any help.
EDIT: To be more thorough, the error is "The type for namespace 'Homepage' does not exist in 'Umbraco.Cms.Web.Common.PublishedModels'
There's are few things to notice here:
1)
The error you see is expected when using PureLive mode in ModelsBuilder.
You should be able to build the solution, even when there are compile-time errors in views, if you have the following setting in the project file (Default when using the Umbraco templates):
<!--Set this to true ModelsBuilder mode is not PureLive -->
<PropertyGroup>
<RazorCompileOnBuild>false</RazorCompileOnBuild>
</PropertyGroup>
2)
The mode of the embedded ModelsBuilder can be changed in any of the JSON files using this code snippet:
We had an issue where the models just would not work in the default location. (/umbraco/models), even custom classes we added here could not be discovered.
You can change the default models location though the configuration settings to see if you are running into the same issue as we did.
Note that the default location is added as type None by default. You will need to add these as Content, like you did in v8, as soon as you use AppData.
namespace Umbraco.Cms.Core.Configuration
{
/// <summary>Defines the models generation modes.</summary>
public enum ModelsMode
{
/// <summary>Do not generate strongly typed models.</summary>
/// <remarks>
/// This means that only IPublishedContent instances will be used.
/// </remarks>
Nothing,
/// <summary>
/// Generate models in memory.
/// When: a content type change occurs.
/// </summary>
/// <remarks>The app does not restart. Models are available in views exclusively.</remarks>
InMemoryAuto,
/// <summary>
/// Generate models as *.cs files.
/// When: generation is triggered.
/// </summary>
/// <remarks>Generation can be triggered from the dashboard. The app does not restart.
/// Models are not compiled and thus are not available to the project.</remarks>
SourceCodeManual,
/// <summary>
/// Generate models as *.cs files.
/// When: a content type change occurs, or generation is triggered.
/// </summary>
/// <remarks>Generation can be triggered from the dashboard. The app does not restart.
/// Models are not compiled and thus are not available to the project.</remarks>
SourceCodeAuto,
}
}
I'm using the Umbraco 9 RC3 and I still have this problem.
The RazorCompileOnBuild is set to false, and in the "appsettings.json" I have configured the Models Builder as AppData, using the keyword SourceCodeManual and generated the models, but the classes cannot be used inside the code because the namespace Umbraco.Cms.Web.Common.PublishedModels.{My_Class_Name} can't be found.
AppData is no more... (as there is no App Data folder!)
The setting has been renamed to be 'SourceCodeManual'
to manually generate the models into source code... (eg then needs to be compiled and so generated files will need to be included in the VS solution at the path they are generated)
I have already tried to set "ModelsMode" to "SourceCodeManual", without success, the autogenerated classes cannot be used inside the code because the namespace Umbraco.Cms.Web.Common.PublishedModels.{My_Class_Name} can't be found.
Here is the list of the parts that I have checked:
inside the .csproj file the "RazorCompileOnBuild" is set to "false";
the property "ModelsMode" in the "appsettings.json" file is set to "SourceCodeManual";
What I noticed is that also for the class PublishedContentModel the "go to" key (F12 in Visual Studio) is not working. Here a screenshot where you can see the class "PublishedContentModel" in white color instead of green color. That's a strange behavior.
It gives me "The type or namespace name 'Test' does not exist in the namespace 'Umbraco.Cms.Web.Common.PublishedModels' (are you missing an assembly reference?)"
No matter if I enter "/umbraco/models", "umbraco/models" or "~/umbraco/models", models folder is empty except for the file ood.flag. (what's the difference between these paths anyway?)
CopyRefAssembliesToPublishDirectory flag was added following a hint in error message but didn't help.
PS: PROBLEM SOLVED by going to Settings -> Models Builder and regenerating models.
Published Models not found - Umbraco 9 on .NET Core
Hey everyone.
I'm attempting to build out a simple site on Umbraco 9 and .NET Core, mainly for testing purposes.
However, PublishedModels is behaving odd. I see the generated models under ~/umbraco/models/, but the razor views do not recognize PublishedModels.XXXX (i.e. @inherits UmbracoViewpage
Does anyone know what I might be doing wrong? Or where in appsettings to change modelbuilder mode since I don't have web.config?
I'd appreciate any help.
EDIT: To be more thorough, the error is "The type for namespace 'Homepage' does not exist in 'Umbraco.Cms.Web.Common.PublishedModels'
Hi Colin..
There's are few things to notice here: 1) The error you see is expected when using PureLive mode in ModelsBuilder. You should be able to build the solution, even when there are compile-time errors in views, if you have the following setting in the project file (Default when using the Umbraco templates):
2) The mode of the embedded ModelsBuilder can be changed in any of the JSON files using this code snippet:
Or you can change it from code, if you expect to use the same mode in all environments, by adding this to your Startup.ConfigureServices
BR/ Bjarke Berg
We had an issue where the models just would not work in the default location. (/umbraco/models), even custom classes we added here could not be discovered.
You can change the default models location though the configuration settings to see if you are running into the same issue as we did.
Note that the default location is added as type
None
by default. You will need to add these asContent
, like you did in v8, as soon as you use AppData.There is an up-for-grabs feature request about writing the Purelive models to another folder, so this folder could be
Content
by default. https://github.com/umbraco/Umbraco-CMS/issues/10213Just a hint. the available ModelsMode are:
Yes! Am I the only one who cannot set the ModelsMode to AppData?
I get the warning:
Bjarke Berg is suggesting to use this mode but now it doesn't build.
Best regards!
The modes has been renamed:
Hi,
I'm using the Umbraco 9 RC3 and I still have this problem.
The
RazorCompileOnBuild
is set tofalse
, and in the "appsettings.json" I have configured the Models Builder asAppData
, using the keywordSourceCodeManual
and generated the models, but the classes cannot be used inside the code because the namespaceUmbraco.Cms.Web.Common.PublishedModels.{My_Class_Name}
can't be found.Do anyone has this problem?
Thank you, Marco
Hi Marco
AppData is no more... (as there is no App Data folder!)
The setting has been renamed to be 'SourceCodeManual'
to manually generate the models into source code... (eg then needs to be compiled and so generated files will need to be included in the VS solution at the path they are generated)
so try setting
in your json configuration file.
regards
Marc
Hi Marc,
thank you for your reply.
I have already tried to set "ModelsMode" to "SourceCodeManual", without success, the autogenerated classes cannot be used inside the code because the namespace
Umbraco.Cms.Web.Common.PublishedModels.{My_Class_Name}
can't be found.Here is the list of the parts that I have checked:
What I noticed is that also for the class
PublishedContentModel
the "go to" key (F12 in Visual Studio) is not working. Here a screenshot where you can see the class "PublishedContentModel" in white color instead of green color. That's a strange behavior.Does anyone have this problem?
Thank you, Marco
I think I have the same problem with Umbraco 9.5.1 freshly installed. Intellisense does not work in cshtml views. After I set the following option:
It gives me "The type or namespace name 'Test' does not exist in the namespace 'Umbraco.Cms.Web.Common.PublishedModels' (are you missing an assembly reference?)"
No matter if I enter "/umbraco/models", "umbraco/models" or "~/umbraco/models", models folder is empty except for the file ood.flag. (what's the difference between these paths anyway?)
CopyRefAssembliesToPublishDirectory flag was added following a hint in error message but didn't help.
PS: PROBLEM SOLVED by going to Settings -> Models Builder and regenerating models.
is working on a reply...