Last post Jun 03, 2019 04:03 PM by Yossu
May 29, 2019 10:43 PM|Yossu|LINK
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
May 30, 2019 05:24 AM|nideeshm|LINK
Go to the file in solution explorer. Right click select properties, set build action as content and copy to output directory as "Copy always"
May 30, 2019 06:56 AM|Xing Zou|LINK
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
May 30, 2019 07:03 AM|Mikesdotnetting|LINK
I have added a folder to the wwwroot folder to hold razor templates that I use for generating emails.
Jun 03, 2019 02:26 PM|Yossu|LINK
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?
Jun 03, 2019 03:59 PM|Mikesdotnetting|LINK
The Partial search locations differ between a Razor Pages app (what I used) and an MVC app. Could that be the difference?
Jun 03, 2019 04:03 PM|Yossu|LINK
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.