Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, May 29, 2019 10:43 PM
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?
Thanks
Visual Studio 2017 Enterprise version 15.9.12
ASP.NET Core 2.2
All replies (6)
Thursday, May 30, 2019 7:03 AM âś…Answered
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.
https://www.mikesdotnetting.com/article/332/rendering-a-partial-to-a-string-in-razor-pages
Thursday, May 30, 2019 5:24 AM
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 6:56 AM
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:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>
Refer to Publish the Views with asp.net core
Best Regards,
Monday, June 3, 2019 2:26 PM
Hello,
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 3:59 PM
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 4:03 PM
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.