From ebb83d4107827053acd111ea72c84c98bdf6952b Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 22 Apr 2025 08:53:42 +0800 Subject: [PATCH 1/2] Add error handling for missing assembly files in BundlingService and improve file path checks in PathHelper --- .../Volo/Abp/Cli/Bundling/BundlingService.cs | 5 +++++ .../Volo/Abp/Cli/Bundling/PathHelper.cs | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs index 76bc82f570..60bc6c846c 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs @@ -67,6 +67,11 @@ public class BundlingService : IBundlingService, ITransientDependency var frameworkVersion = GetTargetFrameworkVersion(projectFilePath, projectType); var projectName = Path.GetFileNameWithoutExtension(projectFilePath); var assemblyFilePath = projectType == BundlingConsts.WebAssembly? PathHelper.GetWebAssemblyFilePath(directory, frameworkVersion, projectName) : PathHelper.GetMauiBlazorAssemblyFilePath(directory, projectName); + if (assemblyFilePath == null) + { + throw new BundlingException("No assembly file found. Please build the project first."); + } + var startupModule = GetStartupModule(assemblyFilePath); var bundleDefinitions = new List(); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs index 1b6b56adab..546890cf05 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Linq; namespace Volo.Abp.Cli.Bundling; @@ -13,12 +14,15 @@ static internal class PathHelper static internal string GetWebAssemblyFilePath(string directory, string frameworkVersion, string projectFileName) { var outputDirectory = Path.Combine(directory, "bin", "Debug", frameworkVersion); - return Path.Combine(outputDirectory, projectFileName + ".dll"); + var path = Path.Combine(outputDirectory, projectFileName + ".dll"); + return !File.Exists(path) ? null : path; } static internal string GetMauiBlazorAssemblyFilePath(string directory, string projectFileName) { - return Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories).First(f => !f.Contains("android") && f.EndsWith(projectFileName + ".dll")); + return Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories).FirstOrDefault(f => + !f.Contains("android", StringComparison.OrdinalIgnoreCase) && + f.EndsWith(projectFileName + ".dll", StringComparison.OrdinalIgnoreCase)); } static internal string GetWwwRootPath(string directory) From 84c1f7ee45e3aa6d33f321df0b1ce1d35186c642 Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 22 Apr 2025 09:04:38 +0800 Subject: [PATCH 2/2] Refactor assembly file path retrieval in BundlingService and simplify string comparison in PathHelper --- .../Volo/Abp/Cli/Bundling/BundlingService.cs | 4 +++- .../src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs index 60bc6c846c..3ee7cfdea3 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs @@ -66,7 +66,9 @@ public class BundlingService : IBundlingService, ITransientDependency var frameworkVersion = GetTargetFrameworkVersion(projectFilePath, projectType); var projectName = Path.GetFileNameWithoutExtension(projectFilePath); - var assemblyFilePath = projectType == BundlingConsts.WebAssembly? PathHelper.GetWebAssemblyFilePath(directory, frameworkVersion, projectName) : PathHelper.GetMauiBlazorAssemblyFilePath(directory, projectName); + var assemblyFilePath = projectType == BundlingConsts.WebAssembly + ? PathHelper.GetWebAssemblyFilePath(directory, frameworkVersion, projectName) + : PathHelper.GetMauiBlazorAssemblyFilePath(directory, projectName); if (assemblyFilePath == null) { throw new BundlingException("No assembly file found. Please build the project first."); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs index 546890cf05..1618004bb5 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/PathHelper.cs @@ -21,7 +21,7 @@ static internal class PathHelper static internal string GetMauiBlazorAssemblyFilePath(string directory, string projectFileName) { return Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories).FirstOrDefault(f => - !f.Contains("android", StringComparison.OrdinalIgnoreCase) && + !f.Contains("android") && f.EndsWith(projectFileName + ".dll", StringComparison.OrdinalIgnoreCase)); }