abp-framework

ABP Framework can't acces virtual files in Deploy


I'm working with the ABP Framework and I'm implementing my own mail templates.

The project was made using the abp project template. I created the template in my Application module: Acme.Bookstore.Application/Assets/Templates/MyEmailTemplate.tpl. I edited the properties of the file to be embedded.

Then I made an instance of the template definition provider as follows:

public class MyEmailTemplateDefinitionProvider : TemplateDefinitionProvider
{
    public override void Define(ITemplateDefinitionContext context)
    {
        context.Add(
            new TemplateDefinition(
                MyEmailTemplates.MyEmailTemplate,
                displayName: LocalizableString.Create<AccountResource>($"TextTemplate:{MyEmailTemplates.MyEmailTemplate}"),
                layout: StandardEmailTemplates.Layout,
                localizationResource: typeof(AccountResource)
            ).WithVirtualFilePath($"Assets/Templates/MyEmailTemplate.tpl", true)
        );
    }
}

Then I added the following lines to my BookstoreApplicationModule.cs

Configure<AbpVirtualFileSystemOptions>(options =>
        {
            options.FileSets.AddEmbedded<BookstoreApplicationModule>("Acme.Bookstore");
        });

I did all this following this documentation: https://docs.abp.io/en/abp/5.3/Virtual-File-System

When debugging locally all works well, but when I deploy the project it can't access the template file. The error is as follows: Volo.Abp.AbpException: Could not find a file/folder at the location: Assets/Templates/MyEmailTemplate.tpl

I already tried adding the AddEbedded call in the HttpApi.Host module but got the same result. I don't know what I'm missing.

For the record, I'm deploying in an Ubuntu server, but that shouldn't matter.


Solution

  • The problem was that the embedded files weren't being added to the VirtualFileSystem. It worked in develpment because the framework calls:

    if (hostingEnvironment.IsDevelopment())
            {
                Configure<AbpVirtualFileSystemOptions>(options =>
                {
                    ... Some code ...
    
                    options.FileSets.ReplaceEmbeddedByPhysical<BookstoreApplicationModule>(
                        Path.Combine(hostingEnvironment.ContentRootPath,
                            $"..{Path.DirectorySeparatorChar}Acme.Bookstore.Application"));
                });
            }
    

    So the problem didn't arise until I did a dotnet publish.

    I could not figure out why it wasn't working on the Application module but moving the files to the Domain.Shared module fixed it.

    I guess that there is some package or setting missing on the other module but this solution is enough for me.