Reputation: 509
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.)
Upvotes: 11
Views: 4740
Reputation: 397
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.
Upvotes: 0
Reputation: 509
finally I found the solution
<PropertyGroup>
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
</PropertyGroup>
reference: https://www.gitmemory.com/issue/aspnet/AspNetCore/4330/523656476
Upvotes: 18
Reputation: 98
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>
Upvotes: 2