Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: UsingTemplateFromEmbedded for compiled Views in ASP.NET Core 2.1 #115

Open
VaclavElias opened this issue Aug 7, 2018 · 2 comments

Comments

@VaclavElias
Copy link

Hi,

I cannot find any reference for this scenario in your Documentation.

My website name Project.Web compiles to Project.Web.dll and Project.Web.Views.dll.

I have got a standard folder structure and in Views I have got:
~/Views/Email/Alert.cshtml.

This Views folder is automatically compiled to Project.Web.Views.dll.

How can I reference it correctly through UsingTemplateFromEmbedded as the assembly actually doesn't exist at the time of development and the compiled view is not in Project.Web.dll which I could easily reference?

await email.To("[email protected]")
                .Subject("Test Email")
                .UsingTemplateFromEmbedded("Project.Web.Views.cshtml", model, assembly)
                .SendAsync();

Hope that my question makes a sense? :)

Thanks.

@sguryev
Copy link

sguryev commented Nov 9, 2018

I guess you should use the Default Namespace from the project properties and then add the path the to cshtml: Root.Sample.Project.Templates.MyTemplate.cshtml

@sguryev
Copy link

sguryev commented Nov 9, 2018

@lukencode @bjcull
Guys could you please describe a best way practice for using the Embedded views? Let's say we have a library (EmailService) with all the Templates which is shared across the several ASP.NET Core 2.1 projects in the solutions. We should change the Build action of the templates to Embedded resource by adding something like

  <ItemGroup>
    <EmbeddedResource Include="Templates\**" />
  </ItemGroup>

right to the library project.

As is it will cause the runtime error like Cannot find compilation library location for package 'Microsoft.NETCore.App' after publishing.
So we have to go to the published ASP.NET Core 2.1 application csproj file and add the line:

<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

Which causes the publishing of the refs folder (which is pretty big) for the Razor for Embedded and not precompiled views.

Is it a best way? Maybe we shoule precompile Templates instead (since embedded resource doesn't allow to change the template like text file on the fly and requires DLL publishing for updating)?

References I have:
https://stackoverflow.com/questions/51269559/razor-templates-cannot-find-compilation-library-location-for-package/51269560#51269560
toddams/RazorLight#203
aspnet/Mvc#6021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants