Folder in wwwroot is not published RRS feed

  • Question

  • User-1158769213 posted

    I have added a folder to the wwwroot folder to hold razor templates that I use for generating emails. However, when I publish the project, the wwwroot does not contain this folder.

    How do I ensure that the folder is published?


    Visual Studio 2017 Enterprise version 15.9.12
    ASP.NET Core 2.2

    Wednesday, May 29, 2019 10:43 PM


All replies

  • User585649674 posted

    Go to the file in solution explorer. Right click select properties, set build action as content and copy to output directory as "Copy always"

    Thursday, May 30, 2019 5:24 AM
  • User-1764593085 posted

    Hi Yossu,

    The Razor View precompilation is enabled by default in core 2.2, you razor templates ends with .chtml will be packaged into View.dll.

    What's more, only the compiled Views.dll and no .cshtml files or references assemblies required to compile Razor files are deployed with your app.

    Refer to Razor file compilation in ASP.NET Core

    If you would like to disable it, try to set the .csproj file's MvcRazorCompileOnPublish property to false:


    Refer to Publish the Views with asp.net core

    Best Regards,


    Thursday, May 30, 2019 6:56 AM
  • User-821857111 posted

    I have added a folder to the wwwroot folder to hold razor templates that I use for generating emails.
    I would implement these as partial views and add them to the Pages/Shared or Views/Shared folder. Content in the wwwroot folder is intended to be browseable.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 30, 2019 7:03 AM
  • User-1158769213 posted


    Thanks very much for the reply. I tried your code and it worked fine. I had been using the RazorLight Nuget package for this. Didn't realise I could do it with the built-in stuff.

    I had one slight issue though. When I did a sample project (copied yours), I created a Templates folder under Views/Shared, and called the render engine with the string "Templates/MyPartialView.cshtml" which worked fine. I did (seemingly) exactly the same in my real project, but had to use "Views/Shared/Templates/MyPartialView.cshtml" toget it to work.

    Any idea why?

    Thanks again.

    Monday, June 3, 2019 2:26 PM
  • User-821857111 posted

    The Partial search locations differ between a Razor Pages app (what I used) and an MVC app. Could that be the difference?

    Monday, June 3, 2019 3:59 PM
  • User-1158769213 posted

    Yeah could be. I was just surprised at having to include the full path.

    No great deal, all works fine. Thanks again for the help.

    Monday, June 3, 2019 4:03 PM