Browse Source

Refine `GeneratePdbForAssemblies` implementation.

pull/3619/head
sonyps5201314 1 month ago
parent
commit
5625db2a96
  1. 36
      ILSpy/Commands/GeneratePdbContextMenuEntry.cs
  2. 2
      ILSpy/Properties/Resources.resx
  3. 2
      ILSpy/Properties/Resources.zh-Hans.resx

36
ILSpy/Commands/GeneratePdbContextMenuEntry.cs

@ -125,9 +125,30 @@ namespace ICSharpCode.ILSpy @@ -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<LoadedAssembly, PEFile>();
var unsupported = new List<LoadedAssembly>();
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 @@ -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++;

2
ILSpy/Properties/Resources.resx

@ -175,7 +175,7 @@ Are you sure you want to continue?</value> @@ -175,7 +175,7 @@ Are you sure you want to continue?</value>
<value>Entity could not be resolved. Cannot analyze entities from missing assembly references. Add the missing reference and try again.</value>
</data>
<data name="CannotCreatePDBFile" xml:space="preserve">
<value>Cannot create PDB file for {0}, because it does not contain a PE Debug Directory Entry of type 'CodeView'.</value>
<value>Cannot create PDB file for {0} because the PE debug directory type 'CodeView' is missing.</value>
</data>
<data name="CheckAgain" xml:space="preserve">
<value>Check again</value>

2
ILSpy/Properties/Resources.zh-Hans.resx

@ -176,7 +176,7 @@ @@ -176,7 +176,7 @@
<value>无法解析实体。可能是由于缺少程序集引用。请添加缺少的程序集并重试。</value>
</data>
<data name="CannotCreatePDBFile" xml:space="preserve">
<value>无法创建为{0}创建PDB文件,因为它不包含PE调试目录类型 'CodeView'.</value>
<value>不能为 {0} 创建PDB文件,因为缺少PE调试目录类型 'CodeView'。</value>
</data>
<data name="CheckAgain" xml:space="preserve">
<value>再次检查</value>

Loading…
Cancel
Save