<bdo id='g8YVK'></bdo><ul id='g8YVK'></ul>
  • <legend id='g8YVK'><style id='g8YVK'><dir id='g8YVK'><q id='g8YVK'></q></dir></style></legend>

      <small id='g8YVK'></small><noframes id='g8YVK'>

      1. <i id='g8YVK'><tr id='g8YVK'><dt id='g8YVK'><q id='g8YVK'><span id='g8YVK'><b id='g8YVK'><form id='g8YVK'><ins id='g8YVK'></ins><ul id='g8YVK'></ul><sub id='g8YVK'></sub></form><legend id='g8YVK'></legend><bdo id='g8YVK'><pre id='g8YVK'><center id='g8YVK'></center></pre></bdo></b><th id='g8YVK'></th></span></q></dt></tr></i><div id='g8YVK'><tfoot id='g8YVK'></tfoot><dl id='g8YVK'><fieldset id='g8YVK'></fieldset></dl></div>

        <tfoot id='g8YVK'></tfoot>
      2. 如何禁用 net core 2.1+/net 5 中的预编译视图进行调试?

        时间:2023-07-11
        <legend id='c5bcP'><style id='c5bcP'><dir id='c5bcP'><q id='c5bcP'></q></dir></style></legend>
        <tfoot id='c5bcP'></tfoot>

              • <bdo id='c5bcP'></bdo><ul id='c5bcP'></ul>

                <small id='c5bcP'></small><noframes id='c5bcP'>

                <i id='c5bcP'><tr id='c5bcP'><dt id='c5bcP'><q id='c5bcP'><span id='c5bcP'><b id='c5bcP'><form id='c5bcP'><ins id='c5bcP'></ins><ul id='c5bcP'></ul><sub id='c5bcP'></sub></form><legend id='c5bcP'></legend><bdo id='c5bcP'><pre id='c5bcP'><center id='c5bcP'></center></pre></bdo></b><th id='c5bcP'></th></span></q></dt></tr></i><div id='c5bcP'><tfoot id='c5bcP'></tfoot><dl id='c5bcP'><fieldset id='c5bcP'></fieldset></dl></div>
                    <tbody id='c5bcP'></tbody>

                  本文介绍了如何禁用 net core 2.1+/net 5 中的预编译视图进行调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  昨天我更新到net core 2.1.

                  Yesterday I updated to net core 2.1.

                  现在,如果我正在调试,视图会被预编译,这在启动过程中当然需要很长时间......是否可以退回到以前的行为,如果需要,视图会及时编译?

                  Now if I am debugging, the views getting precompiled, which ofcourse takes a long time during startup... Is it possible to fall back to the previous behavior, where the Views are compiled just in time, if it is needed?

                  我的 csproj 中没有与预编译相关的参考资料.它是来自元包的东西吗?

                  I have no reference related to precompilation in my csproj. Is it something that comes from the meta package?

                    <ItemGroup>
                      <PackageReference Include="JetBrains.Annotations" Version="11.1.0" />
                      <PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" />
                      <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0" PrivateAssets="All" />
                      <PackageReference Include="Swashbuckle.AspNetCore" Version="2.5.0" />
                      <!--<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />-->
                    </ItemGroup>
                  

                  推荐答案

                  .net core >= 3 (也叫.net 5)

                  Microsoft 创建了一个 Nuget 包.这是此处记录.

                  只需参考 Microsoft.AspNetCore.Mvc.Razor.有条件地在 .csproj 文件中添加 RuntimeCompilation.不要忘记调整版本,你实际使用的.

                  Just reference Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation in your .csproj file conditionally. Don't forget to adjust the version, you actualy use.

                  <PackageReference
                      Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
                      Version="3.1.0"
                      Condition="'$(Configuration)' == 'Debug'" />
                  

                  同时配置您的服务

                      public void ConfigureServices(IServiceCollection services)
                      {
                          // your MVC Builder (AddRazorPages/AddControllersWithViews)
                          IMvcBuilder builder = services.AddRazorPages();
                  
                  #if DEBUG
                              // Only use Runtime Compilation on Debug
                              if (Env.IsDevelopment())
                              {
                                  builder.AddRazorRuntimeCompilation();
                              }
                  #endif
                      }
                  

                  当然,当你想通用运行时编译时,即使发布,你也不需要所有的条件.

                  Ofcourse, when you want to general use Runtime Compilation, even when published, you don't need all the conditions.

                  这可以使用属性 .csproj 文件中的 -razor-sdk" rel="noreferrer">RazorCompileOnBuild:

                  This can be accomplished using the property RazorCompileOnBuild in the .csproj file:

                  <PropertyGroup>
                    <TargetFramework>netcoreapp2.1</TargetFramework>
                    <RazorCompileOnBuild>false</RazorCompileOnBuild>
                    <RazorCompileOnPublish>true</RazorCompileOnPublish>
                  </PropertyGroup>
                  

                  这样 Razor 文件仅在发布期间进行预编译.

                  This way the Razor files are only precompiled during publishing.

                  根据用例,您还想根据构建配置进行配置:

                  Depending on the usecase you also want to configure this depending on the build configuration:

                  <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
                    <RazorCompileOnBuild>false</RazorCompileOnBuild>
                    <RazorCompileOnPublish>true</RazorCompileOnPublish>
                  </PropertyGroup>
                  

                  这篇关于如何禁用 net core 2.1+/net 5 中的预编译视图进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 ASP.net Core 中添加 js 和 css 文件? 下一篇:从 ASP.NET 5 Beta 4 升级到 Beta 5 时出错

                  相关文章

                  • <bdo id='rVGlD'></bdo><ul id='rVGlD'></ul>
                1. <small id='rVGlD'></small><noframes id='rVGlD'>

                  1. <tfoot id='rVGlD'></tfoot>
                    <i id='rVGlD'><tr id='rVGlD'><dt id='rVGlD'><q id='rVGlD'><span id='rVGlD'><b id='rVGlD'><form id='rVGlD'><ins id='rVGlD'></ins><ul id='rVGlD'></ul><sub id='rVGlD'></sub></form><legend id='rVGlD'></legend><bdo id='rVGlD'><pre id='rVGlD'><center id='rVGlD'></center></pre></bdo></b><th id='rVGlD'></th></span></q></dt></tr></i><div id='rVGlD'><tfoot id='rVGlD'></tfoot><dl id='rVGlD'><fieldset id='rVGlD'></fieldset></dl></div>

                      <legend id='rVGlD'><style id='rVGlD'><dir id='rVGlD'><q id='rVGlD'></q></dir></style></legend>