是否可以部署未编译的ASP.NET Razor Pages网站? [英] Is it possible to deploy an uncompiled ASP.NET Razor Pages website?

查看:140
本文介绍了是否可以部署未编译的ASP.NET Razor Pages网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以将ASP.NET Razor Pages网站的源代码复制到Windows Web服务器并使其运行而无需发布/编译?

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/compiled?

类似于ASP.NET Web Forms网站可以在其中上载源代码(* .aspx和* .aspx.cs文件)并在运行时进行编译的网站吗?

Similar to what you can do with ASP.NET Web Forms websites where you upload the source code (*.aspx and *.aspx.cs files) and they compile at runtime?

我看到了有关 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 的一些信息,但是我不确定这是否是我想要的以及如何使用它.

I saw something about Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation but I wasn't sure if this is what I was after and how to use it.

这是可能的,以及有关如何做到的任何指导或链接吗?

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

PS.我敢肯定这不是一个好习惯,但还是想得到一个答案...谢谢.

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

推荐答案

这是可能的,以及有关如何做到的任何指导或链接吗?

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

PS.我敢肯定这不是一个好习惯,但仍然想要一个答案

有一种方法可以允许部署未编译"的邮件. *.cshtml .假设您正在使用ASP.NET Core 3.1:

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

  1. 首先,添加对 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 的程序包引用:

<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.*" />

  • 更改您的服务以允许运行时编译:

  • Change your services to allow Runtime Compilation:

    
     services.AddRazorPages().AddRazorRuntimeCompilation();
     

  • 配置自定义任务,以复制源代码以在您的 *.csproj 文件中发布dir:

  • Configure a custom Task to copy the source code to publish dir in your *.csproj file:

    <ItemGroup>
        <ViewFiles Include="$(ProjectDir)\Pages\**\*.cshtml" />
    </ItemGroup>
    <Target Name="CopyViewFilesAfterPublish" AfterTargets="Publish">
        <Copy SourceFiles="@(ViewFiles)" 
          DestinationFolder="$(PublishDir)\Pages\%(RecursiveDir)" 
        />
    </Target>
    

  • 演示

    我发布了RazorPage WebApp并将其托管在 IIS 上.然后我们可以动态更改 Pages/**/*.cshtml 视图:

    Demo

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

    这篇关于是否可以部署未编译的ASP.NET Razor Pages网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆