Search code examples
asp.net-core-mvcweb-deployment.net-6.0

Where i can find my pages cshtml after Deploy in NET 6


I am developing a website in asp.net mvc with NET 6 and when I deploy I cannot find anymore the cshtml pages, but a lot of folders, dll and an .exe.

The problem is that it looks like I need to update all the website each time I modify one single page.

Is there a way to put online only the modified page cshtml without deploying the entire website?


Solution

  • 1. You need add Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package.

    2. You also need Copy the cshtml when you deploy.

    So my .csproj file like:

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
      <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.2" />
      </ItemGroup>
    
      <ItemGroup>
        <ViewFiles Include="$(ProjectDir)\Views\**\*.cshtml" />
      </ItemGroup>
      
      <Target Name="CopyViewFilesAfterPublish" AfterTargets="Publish">
        <Copy SourceFiles="@(ViewFiles)"
          DestinationFolder="$(PublishDir)\Views\%(RecursiveDir)"
        />
      </Target>
    
    </Project>
    

    Test Result:

    1. Find cshtml file in publish file.

    enter image description here

    1. Test in IIS

    enter image description here