Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views and partials not transferred from repository to live/wwwroot #457

Closed
bjarnef opened this issue Sep 30, 2021 · 8 comments
Closed

Views and partials not transferred from repository to live/wwwroot #457

bjarnef opened this issue Sep 30, 2021 · 8 comments

Comments

@bjarnef
Copy link

bjarnef commented Sep 30, 2021

Issue description

I am migrating a project from Umbraco v8 to v9 and almost got it working.
I have deployed revisions which are extracted on live/remote environment on Umbraco 9.

I have also deployed existing template views and partials to remote environment, which end up just fine in /site/repositiory when looking in Kudo. The templates are also moved to /site/wwwroot, but these are empty and the partials are not transferred.

image

/site/repository

image

image

/site/wwwroot

image

image

So it looks like this in backoffice:

image

@sitereactor
Copy link

You have cut off the most interesting part of the screenshots 😅 .... can you post two things to help me check what is going on

  1. The location of the Views/Partials folder(s) in the git repository (from the root of the repository folder)
  2. The content of your csproj file (UmbracoProject.csproj if you haven't renamed it)

@sitereactor
Copy link

FWIW I have a structure like this (locally) and it copies all the files under Views (recursive) to the /site/wwwroot/Views folder

image

Repository
image

wwwroot
image

@bjarnef
Copy link
Author

bjarnef commented Sep 30, 2021

@sitereactor the location of Views/Partials folders in Kudo is this:

Repository

image

wwwroot

image

The project structure locally is like this:

image

The UmbracoProject.csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <DefaultItemExcludes>$(DefaultItemExcludes);App_Plugins/**;</DefaultItemExcludes>
        <DefaultItemExcludes>$(DefaultItemExcludes);umbraco/**;</DefaultItemExcludes>
        <DefaultItemExcludes>$(DefaultItemExcludes);wwwroot/media/**;</DefaultItemExcludes>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Umbraco.Cloud.Identity.Cms" Version="4.0.39" />
        <PackageReference Include="Umbraco.Cloud.StorageProviders.AzureBlob" Version="4.0.0" />
        <PackageReference Include="Umbraco.Cms" Version="9.0.0" />
        <PackageReference Include="Umbraco.Deploy.Cloud" Version="9.0.0" />
        <PackageReference Include="Umbraco.Deploy.Contrib" Version="9.0.0" />
        <PackageReference Include="Umbraco.Deploy.Forms" Version="9.0.0" />
        <PackageReference Include="Umbraco.Forms" Version="9.0.0" />
    </ItemGroup>



    <ItemGroup>
        <Content Include="App_Plugins/**" CopyToOutputDirectory="Always" />
        <Content Include="umbraco/**" CopyToOutputDirectory="Always" />
        <Content Remove="umbraco/Data/**" />
        <Content Remove="umbraco/Logs/**" />
        <Content Remove="umbraco/mediacache/**" />
        <Content Remove="umbraco/models/**" />
        <Compile Include="umbraco/models/**" Exclude="**/*.flag" />
    </ItemGroup>



    <ItemGroup>
      <None Include="Views\Partials\blocklist\Components\BlockAccordion.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockColumn.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockContactForm.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockCTA.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockFindEducation.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockForm.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockGrid.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockImage.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockImageBox.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockImageGrid.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockLatestNews.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockTestimonialSlider.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockText.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockVideo.cshtml" />
      <None Include="Views\Partials\blocklist\Components\BlockVideoGallery.cshtml" />
      <None Include="Views\Partials\Forms\Themes\standard\Fieldtypes\FieldType.DataConsent.cshtml" />
      <None Include="Views\Partials\Forms\Themes\standard\Fieldtypes\FieldType.Textarea.cshtml" />
      <None Include="Views\Partials\Forms\Themes\standard\Fieldtypes\FieldType.Textfield.cshtml" />
      <None Include="Views\Partials\Forms\Themes\standard\Form.cshtml" />
    </ItemGroup>

    <!-- Set this to true if ModelsBuilder mode is not InMemoryAuto-->
    <PropertyGroup>
        <RazorCompileOnBuild>true</RazorCompileOnBuild>
        <RazorCompileOnPublish>true</RazorCompileOnPublish>
    </PropertyGroup>

</Project>

ModelsBuilder mode is set to SourceCodeManual:

"ModelsBuilder": {
    "ModelsDirectory": "~/Models/",
    "ModelsMode": "SourceCodeManual",
    "Enable": true
}

@bjarnef
Copy link
Author

bjarnef commented Sep 30, 2021

@sitereactor okay, so I just changed this part in UmbracoProject.csproj so RazorCompileOnPublish now is false which it is by default.

<!-- Set this to true if ModelsBuilder mode is not InMemoryAuto-->
<PropertyGroup>
     <RazorCompileOnBuild>true</RazorCompileOnBuild>
     <RazorCompileOnPublish>false</RazorCompileOnPublish>
</PropertyGroup>

I deployed this change and now the template views and partial views are copied to /site/wwwroot/Views folder.
Is that expected?

I guess only RazorCompileOnBuild should be set to true when not using InMemoryAuto ModelsBuilder mode. Not RazorCompileOnPublish.

@sussexrick
Copy link

@bjarnef @sitereactor This is a duplicate of my issue #455. Pasting that here as this one got the attention:

On the v9 launch event one of the speakers said view compilation is disabled by default, but you recommend enabling it for production, so I went looking...

In the default csproj file you get with a v9 project on Cloud you get this:

  <!-- Set this to true if ModelsBuilder mode is not InMemoryAuto-->
    <PropertyGroup>
        <RazorCompileOnBuild>false</RazorCompileOnBuild>
        <RazorCompileOnPublish>false</RazorCompileOnPublish>
    </PropertyGroup>

I don't want InMemoryAuto, I prefer working with SourceCodeAuto, so I changed both values to true and redeployed to Cloud. Here's what I found:

  • If both values are false you get the *.cshtml views in the Views folder, but you don't get UmbracoProject.Views.dll
  • You need <RazorCompileOnBuild>true</RazorCompileOnBuild>, or <RazorCompileOnPublish>true</RazorCompileOnPublish> will fail with an error that UmbracoProject.Views.pdb is not found.
  • If both values are true you get UmbracoProject.Views.dll but the Views folder has no *.cshtml files in it.

All of that makes sense from a pure ASP.NET point of view, but when you try to transfer content from your local environment to live using Umbraco Deploy, it checks that the *.cshtml files are the same in both environments. If they're missing on Cloud you get an error and Deploy doesn't work, so you can't use compiled views and the advice in the csproj file is leading to an error.

Either Deploy needs to be updated to be aware of this, or the *.cshtml files need to always be copied. The latter seems like a better solution since the check by Deploy that the files are up-to-date is a useful one.

@bjarnef
Copy link
Author

bjarnef commented Sep 30, 2021

I also noticed the templates originally deployed to /site/wwwroot/Views was transformed to lowercase, but when I renamed the alias from HomePage to homepage and back to HomePage on live environment it also effect the casing of the templates.

image

@bergmania
Copy link
Member

Looks like we need to have this in the csproj file

    <PropertyGroup>
        <CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
    </PropertyGroup>

@mclausen
Copy link
Member

Howdy there 🤠

Looks like a lot of water has flowed under the bridge since the last update on this issue. From what I can tell, we took a suggestion from @bergmania and added it to the template.

I’m going to assume this ticket has been solved. If not, please feel free to reopen it 👍

Kind regards,
@mclausen
Cloud Platform/Core Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants