8
votes

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.)

2

2 Answers

13
votes

finally I found the solution

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

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

1
votes

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>