Runtime Compilation doesn't work on .net core

625 Views Asked by At

https://learn.microsoft.com/tr-tr/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.1&tabs=netcore-cli I followed that link. First i installed nuget package

Project 'razorapp' has the following package references
   [netcoreapp3.1]: 
   Top-level Package                                        Requested   Resolved
   > Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation      3.1.6       3.1.6  

Then i update Startup.cs file

public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
        }

added .AddRazorRuntimeCompilation() at the end as the doc says.

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

Btw i am using cli in vs code. i am running it with "dotnet run" command when i make changes on "index.cshtml" file editing p tags content or h tags content then i refresh the page on browser nothing changes.
After i run with "dotnet run" output is

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /mnt/c/Users/turke/Desktop/Dev/dotnet/razorapp

Edit: My csproj file:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

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

</Project>

launchSetting.json:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:49928",
      "sslPort": 44326
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "razorapp": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Edit2: It works on visual studio but i don't understand why it doesn't work on cli. I also tried to add runtime compilation at the begining with.
"dotnet new webapp --razor-runtime-compilation"
It doesn't work either.

Edit3:

I used Ubuntu subsystem 20.04 for windows. When i used command prompt for dotnet cli There was no problem. I don't know what is wrong with subsystem but it is better to not use it for dotnet i guess.

0

There are 0 best solutions below