From 5625db2a96d8f05ba6c916dec26c5cfbe69781dc Mon Sep 17 00:00:00 2001 From: sonyps5201314 Date: Sat, 22 Nov 2025 00:50:28 +0800 Subject: [PATCH] Refine `GeneratePdbForAssemblies` implementation. --- ILSpy/Commands/GeneratePdbContextMenuEntry.cs | 36 +++++++++++++------ ILSpy/Properties/Resources.resx | 2 +- ILSpy/Properties/Resources.zh-Hans.resx | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ILSpy/Commands/GeneratePdbContextMenuEntry.cs b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs index a80f89ff9..e453bb7ae 100644 --- a/ILSpy/Commands/GeneratePdbContextMenuEntry.cs +++ b/ILSpy/Commands/GeneratePdbContextMenuEntry.cs @@ -125,9 +125,30 @@ namespace ICSharpCode.ILSpy return; // Ensure at least one assembly supports PDB generation - if (!assemblyArray.Any(a => PortablePdbWriter.HasCodeViewDebugDirectoryEntry(a.GetMetadataFileOrNull() as PEFile))) + var supported = new Dictionary(); + var unsupported = new List(); + foreach (var a in assemblyArray) { - MessageBox.Show(Resources.CannotCreatePDBFile); + try + { + var file = a.GetMetadataFileOrNull() as PEFile; + if (PortablePdbWriter.HasCodeViewDebugDirectoryEntry(file)) + supported.Add(a, file); + else + unsupported.Add(a); + } + catch + { + unsupported.Add(a); + } + } + if (supported.Count == 0) + { + // none can be generated + string msg = string.Format(Resources.CannotCreatePDBFile, ":" + Environment.NewLine + + string.Join(Environment.NewLine, unsupported.Select(u => Path.GetFileName(u.FileName))) + + Environment.NewLine); + MessageBox.Show(msg); return; } @@ -154,15 +175,8 @@ namespace ICSharpCode.ILSpy int processed = 0; foreach (var assembly in assemblyArray) { - if (ct.IsCancellationRequested) - { - output.WriteLine(); - output.WriteLine(Resources.GenerationWasCancelled); - throw new OperationCanceledException(ct); - } - - var file = assembly.GetMetadataFileOrNull() as PEFile; - if (file == null || !PortablePdbWriter.HasCodeViewDebugDirectoryEntry(file)) + // only process supported assemblies + if (!supported.TryGetValue(assembly, out var file)) { output.WriteLine(string.Format(Resources.CannotCreatePDBFile, Path.GetFileName(assembly.FileName))); processed++; diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index 0924816a9..e8b5af669 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -175,7 +175,7 @@ Are you sure you want to continue? Entity could not be resolved. Cannot analyze entities from missing assembly references. Add the missing reference and try again. - Cannot create PDB file for {0}, because it does not contain a PE Debug Directory Entry of type 'CodeView'. + Cannot create PDB file for {0} because the PE debug directory type 'CodeView' is missing. Check again diff --git a/ILSpy/Properties/Resources.zh-Hans.resx b/ILSpy/Properties/Resources.zh-Hans.resx index 2651f17af..20bbc1dce 100644 --- a/ILSpy/Properties/Resources.zh-Hans.resx +++ b/ILSpy/Properties/Resources.zh-Hans.resx @@ -176,7 +176,7 @@ 无法解析实体。可能是由于缺少程序集引用。请添加缺少的程序集并重试。 - 无法创建为{0}创建PDB文件,因为它不包含PE调试目录类型 'CodeView'. + 不能为 {0} 创建PDB文件,因为缺少PE调试目录类型 'CodeView'。 再次检查