如何禁用Net Core 2.1+中的预编译视图以进行调试? [英] How to disable precompiled views in net core 2.1+ for debugging?
问题描述
昨天我更新到了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中没有与预编译相关的参考.是来自meta包的东西吗?
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核心> = 2.1&& < 3
.net core >= 2.1 && < 3
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核心> = 3
Microsoft创建了一个Nuget程序包.这是在此处记录的.
只需在 Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
> .csproj 文件.
<PackageReference
Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
Version="3.1.0"
Condition="'$(Configuration)' == 'Debug'" />
这篇关于如何禁用Net Core 2.1+中的预编译视图以进行调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!