Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 766
Diyar Avatar asked Oct 05 '19 12:10

Diyar


People also ask

How are publish items computed in ASP NET Core?

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.

What is a view in ASP NET Core?

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.

Can I use the Web SDK with an ASP NET Core project?

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.

How to publish all cshtml files in a bin folder?

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.


1 Answers

finally I found the solution

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

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

like image 138
Diyar Avatar answered Nov 15 '22 17:11

Diyar