Is it possible to deploy an uncompiled ASP.NET Razor Pages website?

前端 未结 1 1272
伪装坚强ぢ
伪装坚强ぢ 2021-01-16 01:16

I am wondering if it is possible to copy the source code of an ASP.NET Razor Pages website to a Windows web server and for it to run without it needing to be published/compi

1条回答
  •  半阙折子戏
    2021-01-16 01:53

    Is this possible and any guidance or links on how to do it?

    PS. I'm sure this is not good practice, but would still like an answer

    There's a way to allow deploy "uncompiled" *.cshtml. Assuming you're using ASP.NET Core 3.1:

    1. First of all, add a package reference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation:

      
      
    2. Change your services to allow Runtime Compilation:

       services.AddRazorPages().AddRazorRuntimeCompilation();
       
    3. Configure a custom Task to copy the source code to publish dir in your *.csproj file:

      
          
      
      
          
      
      

    Demo

    I publish a RazorPage WebApp and host it on IIS. And then we can change the Pages/**/*.cshtml views dynamically:

    0 讨论(0)
提交回复
热议问题