Publishing production, views still in the 'views' folder

When following the Runtime Modes documentation to get a published site running in production, i seem to still have all the views in the Views folder even when i am pre-compiling them into the site dll.

I am probably missing something simple. but i am following the docs.

The TL:DR is are the view files suppose to be there when i publish, am i missing something

So for clarity i am doing the following:

Install Umbraco 16

dotnet new install Umbraco.Templates@16.*

Create a new site

dotnet new umbraco -n PublishTest

Add the Clean starter kit to the site

cd ./PublishTest/
dotnet add package Clean

Then I run it to get it working

dotnet run

then i change the development mode models (in appsettings.development.json)

      "Runtime": {
        "Mode": "Development"
      },
      "ModelsBuilder": {
        "ModelsMode": "SourceCodeAuto"
      }

then i

  • restart the site
  • generate the models via the back end dashboard,
  • restart again to check the site is working (in development)

Now i create a appsettings.production.json file as per the docs. i have set a http local host port to use later

{
  "Umbraco": {
    "CMS": {
      "Runtime": {
        "Mode": "Production"
      },
      "Hosting": {
        "Debug": false
      },
      "Global": {
        "UseHttps": true
      },
      "ModelsBuilder": {
        "ModelsMode": "Nothing"
      },
      "WebRouting": {
        "UmbracoApplicationUrl": "https://localhost:5003/"
      },
      "RuntimeMinification": {
        "UseInMemoryCache": true,
        "CacheBuster": "AppDomain"
      }
    }
  }
}

then I remove the two Razor compile lines from the .csproj. so it looks like this.


  <PropertyGroup>
    <!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
    <!--
    <RazorCompileOnBuild>false</RazorCompileOnBuild>
    <RazorCompileOnPublish>false</RazorCompileOnPublish>
    -->
  </PropertyGroup>

Then i build it for good measure

dotnet build -c Release

then i publish it to a folder

dotnet publish --configuration Release --output ../PublishedSite

this published site, still has a views folder with all the file in it ? is this expected

if i then go to the published folder i set a couple of things to make sure i am running in prod and can get to the site.

$Env:ASPNETCORE_ENVIRONMENT = "Production"
$Env:ASPNETCORE_HTTPS_PORTS=5003

then i run the exe out of the folder ?

.\PublishTest.exe

The site runs and is available on https://localhost:5003/umbraco

the “Live Environment” health check tells me i am running in “Production”

but i can see and edit the templates as if they are still on disk (not pre-compiled where it should tell me they are read only)

If i delete the views folder from the published site and start it up again, it just shows me null like they are not there. (so i suspect they are not).

The site still seems to work though , (as if they compiled views are there).


So summary Questions

  • Should the templates appear in the views folder at all when i publish a site ?
  • Am i missing something obvious in the docs
  • Are the docs missing something ?
  • Is v16 behaving as expected here ?
1 Like

Still not sure this is right adding

  <ItemGroup>
    <Content Update="Views/**">
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

to the .csproj file stops the views being copied to the publish folder.

i’ve also noticed the starterkit will then create (some) of them on first boot :frowning: - which is just due to my testing.

After this. the site does have all the templates defined and the site works, but i still get the empty template view in the back office (for the ones that the kit didn’t create - but which exist in the razor)

i can still see and save, but the changes don’t get written to disk?

Am i now at the point of this is the ‘current’ behavior and there are things to report for v16, or am i still missing something

This is normal.

This is why we have this in the csproj:

<PropertyGroup>
  <!-- Razor files are needed for the backoffice to work correctly -->
  <CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
</PropertyGroup>

I say normal, It would be nice if the backoffice worked properly without them there.

ps..
dotnet www.dll --urls=https://localhost:5003/ --configuration Release --environment Production

find this easy than setting environment vars..

Though can never seem to get the non editing of templates and the banner to show..

Just in case localhost url is involved tried setting the url to https://umb.local and corresponding applicationUrl, with a corresponding hosts edit..
and tried https://www.umbracosixteen.com
no joy…

Perhaps running in Kestrel via this means no banner? Could in have to be a production IIS?

And systemInformation from the umbraco logo.. can give you that confidence that things are set correctly (as well as that live environment healthcheck)

Conditionally setting the razor compilation too.. sometimes helps me out when spinning up quick tests…

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
  <!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
  <RazorCompileOnBuild>false</RazorCompileOnBuild>
  <RazorCompileOnPublish>false</RazorCompileOnPublish>
</PropertyGroup>