Views folders are not getting published in .NET Core 3.x

Posted by Raja under Error and Solution on 3/30/2020 | Points: 10 | Views : 1144 | Status : [Member] | Replies : 0

I had developed a .NET Core MVC application and when I was publishing it to host on to the server I noticed that apart from wwwroot no other folders were getting published.

All other folders gets created as .dll like YourProject.Views.dll etc.

I wanted my razor pages to gets into publish folder as it is so that if I need to change a bit here and there in the cshtml pages, I do not need to publish the entire project on the server and upload it again.

After so many trial and error I could figure out following that helped me publish the Views and Areas folder separately under publish folder.

Steps
1. Open your csproj file in Notepad (YourProjectName.csproj)
2. Add following setting under PropertyGroup tag

 <PropertyGroup>
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
</PropertyGroup>

3. Save the file.
4. Close Visual Studio and open the project again.
5. Publish the project and you will notice your Views and Areas folder under Publish folder.

Thanks

Regards,
Raja, USA



Responses

(No response found.)

Login to post response