umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.42k stars 2.67k forks source link

NetCore: Publish not working for default models builder setup #10585

Closed idseefeld closed 3 years ago

idseefeld commented 3 years ago

Which exact Umbraco version are you using? For example: 8.13.1 - don't just write v8

Nightly Build: Umbraco version 9.0.0-preview20210701.67054

Bug summary

For a default Umbraco V9 setup publishing is not working. I tried a folder publish which leads to the following error message:

Error CS0234: The type or namespace name '[DOCUMENT TYPE NAME]' does not exist in the namespace 
'Umbraco.Cms.Web.Common.PublishedModels' (are you missing an assembly reference?)

[DOCUMENT TYPE NAME] replaces of course a concrete document typ name. 😉

Specifics

The error message tells me the publish process tries to precompile the views. Because of the auto generated, strongly typed template (in the IDE you can see the type is unknown) this is not possible.

I could fix the issue by configuring SourceCodeManual in appSettings.json and deleting folder \Umbraco\Data\TEMP:

"ModelsBuilder": {
    "ModelsMode": "SourceCodeManual",
    "Enable": true
}

You have to run the back office and build the model before you retry the publishing.

Steps to reproduce

  1. Create a new Umbraco Version 9 solution in Visual Studio (Umbraco template from nightly build)
  2. Build, start Debugging, create one document type with template (add content node)
  3. Stop debugging and select Publish... e.g. on projects context menu
  4. I tried Folder publish, but guess it does not matter which method you chose

Expected result / actual result

No response

nikolajlauridsen commented 3 years ago

Hey @idseefeld, thanks for reporting, I was able to reproduce, and you're exactly right, it's because publishing tries to precompile the views. We already have a project property to stop views from compiling on build, however, we don't have one for publishing it seems.

You can fix this for now by opening your project's .csproj file, and scrolling down to the bottom where you'll find a property group that has a RazorCompileOnBuild property set to false, add the RazorCompileOnPublish property and set it false as well, and now you can publish without precompiling views, the property group should look like this afterwards:

<PropertyGroup>
    <RazorCompileOnBuild>false</RazorCompileOnBuild>
    <RazorCompileOnPublish>false</RazorCompileOnPublish>
</PropertyGroup>
nikolajlauridsen commented 3 years ago

Fixed in #10594