Open Closed

Ability for the application to directly use the physical file at development time #2843


User avatar
0
Radoslav created

HI,

This is about this documentation page: https://docs.abp.io/en/abp/latest/Virtual-File-System#dealing-with-embedded-files-during-development Dealing With Embedded Files During Development

I think this sentence: "physical file at development time" should be changed to physical file at development time (when a host app is run at development time - in run mode)

I am confused about what modules I would need to include when I use AbpVirtualFileSystemOptions.FileSets.ReplaceEmbeddedByPhysical method. I am using some existing web applications as examples.

I need to uderstand this: **The example below shows an application that depends on a module (MyModule) that contains embedded files. The application can access to the source code of the module at development time. ** When I always start my web project I would say that any change I make within the solution will result in comilation and only then the web app will run, which means embeded files will be also compiled into depended assemblies and will be avalable to the web app. Is this only about changing files marked as embeded at run time (once the web app is running) that the abp virtual file system will serve these changed physical files?

First case is when I have the theme AdminLTETheme project added to the solution and I can see **AbpAspNetCoreMvcUIAdminLTEThemeModule **being added to the web Commerce.Web.cspro. **Why? ** I can see that CommerceWebModule, CommerceDomainSharedModule and CommerceApplicationContractsModule are being added. **Why? **

Is the rule that whenever I mark a file as embeded and I intend to change it at run time, I will need to add its module to the host app?

D:\Projects\Commerce\src\Commerce.Web\CommerceWebModule.cs

Configure<AbpVirtualFileSystemOptions>(options =>
{
	options.FileSets.ReplaceEmbeddedByPhysical<CommerceDomainSharedModule>(Path.Combine(contentRoot, $"..{separator}Commerce.Domain"));
	options.FileSets.ReplaceEmbeddedByPhysical<CommerceApplicationContractsModule>(Path.Combine(contentRoot, $"..{separator}Commerce.Application.Contracts"));
	options.FileSets.ReplaceEmbeddedByPhysical<CommerceWebModule>(hostingEnvironment.ContentRootPath);
	options.FileSets.ReplaceEmbeddedByPhysical<**AbpAspNetCoreMvcUIAdminLTEThemeModule**>(Path.Combine(contentRoot, $"..{separator}..{separator}modules{separator}Commerce.Themes{separator}src{separator}ABP-Framework-Theme-Using-AdminLTE3-Template{separator}src{separator}Indo.Abp.AspNetCore.Mvc.UI.Theme.AdminLTE"));
});

This is the second case. I am not so sure if all of these modules needs to be added.

D:\abp\modules\cms-kit\host\Volo.CmsKit.Web.Unified\CmsKitWebUnifiedModule.cs

public class CmsKitWebUnifiedModule : AbpModule
    public override void ConfigureServices(ServiceConfigurationContext context)

if (hostingEnvironment.IsDevelopment())
{
	Configure<AbpVirtualFileSystemOptions>(options =>
	{
		options.FileSets.ReplaceEmbeddedByPhysical<AbpAspNetCoreMvcUiThemeSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework/src{0}Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared", Path.DirectorySeparatorChar)));

		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Domain.Shared", Path.DirectorySeparatorChar)));
		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Domain", Path.DirectorySeparatorChar)));

		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitCommonWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Common.Web", Path.DirectorySeparatorChar)));
		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitPublicWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Public.Web", Path.DirectorySeparatorChar)));
		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitAdminWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Admin.Web", Path.DirectorySeparatorChar)));

		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Application.Contracts", Path.DirectorySeparatorChar)));
		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Application", Path.DirectorySeparatorChar)));
		options.FileSets.ReplaceEmbeddedByPhysical<CmsKitWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.CmsKit.Web", Path.DirectorySeparatorChar)));
	});
}

5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    If a module is using virtual files, ReplaceEmbeddedByPhysical can be used.

    If the files in this module do not change frequently, you can ignore it.

    The physical-file-provider will get file changes in real time.

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/file-providers?view=aspnetcore-6.0#physical-file-provider

  • User Avatar
    0
    Radoslav created

    @mailming When I will know if I am using virtual files? Is this necessary when adding a theme project to your solution and when you want to reference that theme and use it in your module (host app)? If yes, what is using virtual files: host app module or theme module? Can you please clarify as I asked similar question above. I mentioned development time too. Can you comment.

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    If the project has localization files or web projects that contain js, css, or any embedded file resources such as any email templates, the virtual file system is used by default.

    If these resource files you need to change frequently during development you can use ReplaceEmbeddedByPhysical

    https://docs.abp.io/en/abp/latest/Virtual-File-System#dealing-with-embedded-files-during-development

  • User Avatar
    0
    Radoslav created

    Thanks @mailming,

    To conclude. If a project (module A) doesn't have embeded resources: js, css, json, razor files or entything with that is marked as embeded resource and if the module is referenced by another module B or host project P we don't need to add ReplaceEmbeddedByPhysical and point to that module A in either module B or host project P.

    If this is correct there are many places in ABP framework, modules, samples where we don't have consistent ReplaceEmbeddedByPhysical pointers to only those modules that actually have embeded resources. Maybe we have them to enable referenced modules to be able to host some embeded resources and we do it just in case.

    Can you please clarify so I can confidently use ReplaceEmbeddedByPhysical when I am dealing with runtime changes of underlying resources that should be reflected in the GUI.

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can develop it as we discussed above.

    What is needed is the ability for the application to directly use the physical file at development time and a browser refresh reflects any change made in the JavaScript file. The ReplaceEmbeddedByPhysical method makes all this possible.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11