Asp.net core 3.0 Publish Views files (.cshtml) on Publish or on Build
Asked Answered
O

3

10

I want to edit Razor view during runtime as publish Views or Razor Page .cshtml to Publish folder,

in Asp.net core 2.1 with

  <PropertyGroup>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
  </PropertyGroup>

I could to publish Views and edit it during runtime, but with Asp.net core 3.0 this feature not works for me.

Do you know how publish Views during publish? (I do not want to pack Views in dll file I want RAW .cshtml file.)

Outbound answered 5/10, 2019 at 12:6 Comment(0)
O
15

finally I found the solution

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

reference: https://www.gitmemory.com/issue/aspnet/AspNetCore/4330/523656476

Outbound answered 5/10, 2019 at 12:43 Comment(3)
Can you clarify where that goes, please?Abdul
In your project file (.csproj) (although it didn't work for me)Hover
That link is dead. Here's an up-to-date link. This did work for me in .net 6. learn.microsoft.com/en-us/aspnet/core/razor-pages/…Heterodoxy
P
2

some files to get published with your app, you can still use the known mechanisms in csproj for that (for example, the element).

csproj file contain :

<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
    <ItemGroup>
      <Views Include="Views\**" />
    </ItemGroup>
    <Copy SourceFiles="@(Views)" DestinationFolder="$(PublishDir)%(Views.RelativeDir)" />
  </Target>
Pensile answered 21/1, 2020 at 2:17 Comment(0)
H
0

I had a similar issue. I wanted to include cshtml files in the publish output folder. I right clicked the cshtml files, and had them as content, copy if newer, however my files were not being copied to the publish output folder.

In my case, for some reason, my csproj file also had 2 lines removing the same cshtml files:

<Content Remove="File1.cshtml" />
<Content Remove="File2.cshtml" />

Once I removed these 2 lines, the files were included.

Hover answered 28/4, 2023 at 3:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.