简体   繁体   中英

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

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

finally I found the solution

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

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM