From 912a909a0b1af8e8819119775ff85acd0cf9be4b Mon Sep 17 00:00:00 2001 From: maliming Date: Sat, 8 Mar 2025 14:28:41 +0800 Subject: [PATCH] Map static assets if there is a blazor client project. --- .../Builder/AbpApplicationBuilderExtensions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs index f0ca14657b..9103c93bff 100644 --- a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpApplicationBuilderExtensions.cs @@ -9,8 +9,10 @@ using Microsoft.AspNetCore.StaticAssets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Volo.Abp; +using Volo.Abp.AspNetCore; using Volo.Abp.AspNetCore.Auditing; using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.AspNetCore.Security; @@ -184,6 +186,21 @@ public static class AbpApplicationBuilderExtensions // https://github.com/dotnet/aspnetcore/issues/59673 app.UseStaticFiles(); + if (!staticAssetsManifestPath.IsNullOrWhiteSpace()) + { + app.ApplicationServices.GetRequiredService>().LogWarning( + $"The staticAssetsManifestPath({staticAssetsManifestPath}) parameter your provided in MapAbpStaticAssets method is ignored in development mode."); + } + + var blazorClientStaticAssetsManifest = Path.Combine(AppContext.BaseDirectory, $"{environment.ApplicationName}.Client.staticwebassets.endpoints.json"); + if (File.Exists(blazorClientStaticAssetsManifest)) + { + // We have a blazor client project and we need to map the static assets from the client project. + var blazorHostStaticAssetsManifest = Path.Combine(AppContext.BaseDirectory, $"{environment.ApplicationName}.staticwebassets.endpoints.json"); + File.Copy(blazorClientStaticAssetsManifest, blazorHostStaticAssetsManifest, true); + return endpoints.MapStaticAssets(blazorHostStaticAssetsManifest); + } + // Volo.Abp.AspNetCore.staticwebassets.endpoints.json is an empty file. Just compatible with the return type of MapAbpStaticAssets. var tempStaticAssetsManifestPath = Path.Combine(AppContext.BaseDirectory, "Volo.Abp.AspNetCore.staticwebassets.endpoints.json"); if (!File.Exists(tempStaticAssetsManifestPath))