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.)
The publish items are computed (the files that are needed to publish). The project is published (the computed files are copied to the publish destination). When an ASP.NET Core project references Microsoft.NET.Sdk.Web in the project file, an app_offline.htm file is placed at the root of the web app directory.
A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup.
Because the Web SDK depends on the .NET Core SDK, either item can be used in an ASP.NET Core project. The following example's <ItemGroup> element demonstrates copying a folder located outside of the project directory to a folder of the published site. Any files added to the following markup's <ItemGroup> are included by default.
All good, until you choose to use wildcards to include all cshtml files (**.cshtml). The dotnet command will look for all cshtml files in your application folder which will include the ones in your bin folder, then include these in the published output.
finally I found the solution
<PropertyGroup>
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
</PropertyGroup>
reference: https://www.gitmemory.com/issue/aspnet/AspNetCore/4330/523656476
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With