3

I am developing ASP.NET Core 5.0.1 project and I want to know how can I disable precompiled views while I developing. It takes long time to reload page if I change some html code and I don't want that. I know it is useful at product but I want to disable on development.

Anyone can help me?

UPDATE

app.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>

Startup.cs

public class Startup
{
    public void ConfigureServices(IServiceCollection services, IWebHostEnvironment env)
    {
        services.AddControllersWithViews();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRouting();
        app.UseEndpoints(routes =>
        {
            routes.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}"
            );
        });
    }
}
serhattsnmz
  • 137
  • 9
  • 2
    have you tried the accepted solution in this question https://stackoverflow.com/questions/50778521/how-to-disable-precompiled-views-in-net-core-2-1-for-debugging ? If you've tried it, it would be nice if you include the code you tried as well as referencing the link from that already answered question. It's accepted and highly voted so it does seem to work. If possible, try a simple demo project targeting .NET Core of lower versions and see if it works. Get back to your current project and try it. All such attempts should be included in your question to show that you've really tried hard. – King King Jan 18 '21 at 19:29
  • 2
    BTW when trying the above solution, be sure to clean all the output files before trying debugging yourself. The existing view compiled files may make you misunderstand that it's not working but in fact it may do work. – King King Jan 18 '21 at 19:30
  • Thanks for answering @KingKing, I've both tried the link you gave me and the doc here https://docs.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-5.0&tabs=visual-studio but I cannot do what I want to do. I tried both 3.1 and 5.0 and both did not work. Does it could be because I am using "ControllersWithViews"? Not: I sure to clean all output files and rebuild project. – serhattsnmz Jan 18 '21 at 23:45

1 Answers1

0

Finally I've found the answer. When using AddControllersWithViews() on ASP.NET Core 3.1 and ASP.NET Core 5.0, the following solutions are not working:

The solution is simple than I think actually.

Update .csproj file as follow, without any condition:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.1" />
  </ItemGroup>

</Project>

Update ConfigureServices method as follow:

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews().AddRazorRuntimeCompilation();
}

It's done. When debug, program will not wait to compile view files.

serhattsnmz
  • 137
  • 9