Browse Source

Add some loading information to AssemblyReferenceTreeNode/ReferenceFolderTreeNode.

pull/848/head
Siegfried Pammer 8 years ago
parent
commit
7ec5156f16
  1. 5
      ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs
  2. 11
      ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs
  3. 24
      ICSharpCode.Decompiler/DotNetCore/UnresolvedAssemblyNameReference.cs
  4. 2
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  5. 42
      ILSpy/LoadedAssembly.cs
  6. 16
      ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs
  7. 3
      ILSpy/TreeNodes/ReferenceFolderTreeNode.cs

5
ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs

@ -40,16 +40,19 @@ namespace ICSharpCode.Decompiler
readonly string targetFrameworkId; readonly string targetFrameworkId;
readonly string version; readonly string version;
readonly string dotnetBasePath = FindDotNetExeDirectory(); readonly string dotnetBasePath = FindDotNetExeDirectory();
readonly Dictionary<string, UnresolvedAssemblyNameReference> loadInfo;
public DotNetCorePathFinder(string parentAssemblyFileName, string targetFrameworkId, string version) public DotNetCorePathFinder(string parentAssemblyFileName, string targetFrameworkId, string version, Dictionary<string, UnresolvedAssemblyNameReference> loadInfo)
{ {
this.assemblyName = Path.GetFileNameWithoutExtension(parentAssemblyFileName); this.assemblyName = Path.GetFileNameWithoutExtension(parentAssemblyFileName);
this.basePath = Path.GetDirectoryName(parentAssemblyFileName); this.basePath = Path.GetDirectoryName(parentAssemblyFileName);
this.targetFrameworkId = targetFrameworkId; this.targetFrameworkId = targetFrameworkId;
this.version = version; this.version = version;
this.loadInfo = loadInfo;
var depsJsonFileName = Path.Combine(basePath, $"{assemblyName}.deps.json"); var depsJsonFileName = Path.Combine(basePath, $"{assemblyName}.deps.json");
if (!File.Exists(depsJsonFileName)) { if (!File.Exists(depsJsonFileName)) {
loadInfo.AddMessage(assemblyName, MessageKind.Error, $"{assemblyName}.deps.json could not be found!");
return; return;
} }

11
ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs

@ -29,5 +29,16 @@ namespace ICSharpCode.Decompiler
return string.Empty; return string.Empty;
} }
public static void AddMessage(this Dictionary<string, UnresolvedAssemblyNameReference> container, string fullName, MessageKind kind, string message)
{
if (container == null)
throw new ArgumentNullException(nameof(container));
if (!container.TryGetValue(fullName, out var referenceInfo)) {
referenceInfo = new UnresolvedAssemblyNameReference(fullName);
container.Add(fullName, referenceInfo);
}
referenceInfo.Messages.Add((kind, message));
}
} }
} }

24
ICSharpCode.Decompiler/DotNetCore/UnresolvedAssemblyNameReference.cs

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSharpCode.Decompiler
{
public sealed class UnresolvedAssemblyNameReference
{
public string FullName { get; }
public bool HasErrors => Messages.Any(m => m.Item1 == MessageKind.Error);
public List<(MessageKind, string)> Messages { get; } = new List<(MessageKind, string)>();
public UnresolvedAssemblyNameReference(string fullName)
{
this.FullName = fullName;
}
}
public enum MessageKind { Error, Warning, Info }
}

2
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -260,6 +260,7 @@
<Compile Include="Documentation\XmlDocumentationProvider.cs" /> <Compile Include="Documentation\XmlDocumentationProvider.cs" />
<Compile Include="DotNetCore\DotNetCorePathFinder.cs" /> <Compile Include="DotNetCore\DotNetCorePathFinder.cs" />
<Compile Include="DotNetCore\DotNetCorePathFinderExtensions.cs" /> <Compile Include="DotNetCore\DotNetCorePathFinderExtensions.cs" />
<Compile Include="DotNetCore\UnresolvedAssemblyNameReference.cs" />
<Compile Include="IL\ControlFlow\AsyncAwaitDecompiler.cs" /> <Compile Include="IL\ControlFlow\AsyncAwaitDecompiler.cs" />
<Compile Include="IL\ControlFlow\ControlFlowGraph.cs" /> <Compile Include="IL\ControlFlow\ControlFlowGraph.cs" />
<Compile Include="IL\ControlFlow\StateRangeAnalysis.cs" /> <Compile Include="IL\ControlFlow\StateRangeAnalysis.cs" />
@ -274,6 +275,7 @@
<Compile Include="IL\Transforms\NullCoalescingTransform.cs" /> <Compile Include="IL\Transforms\NullCoalescingTransform.cs" />
<Compile Include="IL\Transforms\TransformCollectionAndObjectInitializers.cs" /> <Compile Include="IL\Transforms\TransformCollectionAndObjectInitializers.cs" />
<Compile Include="Output\TextTokenWriter.cs" /> <Compile Include="Output\TextTokenWriter.cs" />
<Compile Include="Util\KeyComparer.cs" />
<Compile Include="Util\UnicodeNewline.cs" /> <Compile Include="Util\UnicodeNewline.cs" />
<Compile Include="FlowAnalysis\ControlFlowNode.cs" /> <Compile Include="FlowAnalysis\ControlFlowNode.cs" />
<Compile Include="FlowAnalysis\DataFlowVisitor.cs" /> <Compile Include="FlowAnalysis\DataFlowVisitor.cs" />

42
ILSpy/LoadedAssembly.cs

@ -17,7 +17,9 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
@ -36,6 +38,7 @@ namespace ICSharpCode.ILSpy
readonly string fileName; readonly string fileName;
readonly string shortName; readonly string shortName;
readonly Lazy<string> targetFrameworkId; readonly Lazy<string> targetFrameworkId;
readonly Dictionary<string, UnresolvedAssemblyNameReference> loadedAssemblyReferences = new Dictionary<string, UnresolvedAssemblyNameReference>();
public LoadedAssembly(AssemblyList assemblyList, string fileName, Stream stream = null) public LoadedAssembly(AssemblyList assemblyList, string fileName, Stream stream = null)
{ {
@ -51,8 +54,13 @@ namespace ICSharpCode.ILSpy
this.targetFrameworkId = new Lazy<string>(AssemblyDefinition.DetectTargetFrameworkId, false); this.targetFrameworkId = new Lazy<string>(AssemblyDefinition.DetectTargetFrameworkId, false);
} }
/// <summary>
/// Returns a target framework identifier in the form '&lt;framework&gt;Version=v&lt;version&gt;'.
/// </summary>
public string TargetFrameworkId => targetFrameworkId.Value; public string TargetFrameworkId => targetFrameworkId.Value;
public Dictionary<string, UnresolvedAssemblyNameReference> LoadedAssemblyReferencesInfo => loadedAssemblyReferences;
/// <summary> /// <summary>
/// Gets the Cecil ModuleDefinition. /// Gets the Cecil ModuleDefinition.
/// Can be null when there was a load error. /// Can be null when there was a load error.
@ -77,18 +85,12 @@ namespace ICSharpCode.ILSpy
return module != null ? module.Assembly : null; return module != null ? module.Assembly : null;
} }
} }
public AssemblyList AssemblyList { public AssemblyList AssemblyList => assemblyList;
get { return assemblyList; }
} public string FileName => fileName;
public string FileName { public string ShortName => shortName;
get { return fileName; }
}
public string ShortName {
get { return shortName; }
}
public string Text { public string Text {
get { get {
@ -99,14 +101,10 @@ namespace ICSharpCode.ILSpy
} }
} }
} }
public bool IsLoaded { public bool IsLoaded => assemblyTask.IsCompleted;
get { return assemblyTask.IsCompleted; }
} public bool HasLoadError => assemblyTask.IsFaulted;
public bool HasLoadError {
get { return assemblyTask.IsFaulted; }
}
public bool IsAutoLoaded { get; set; } public bool IsAutoLoaded { get; set; }
@ -266,7 +264,7 @@ namespace ICSharpCode.ILSpy
if (targetFramework.Length != 2) break; if (targetFramework.Length != 2) break;
if (dotNetCorePathFinder == null) { if (dotNetCorePathFinder == null) {
var version = targetFramework[1].Length == 3 ? targetFramework[1] + ".0" : targetFramework[1]; var version = targetFramework[1].Length == 3 ? targetFramework[1] + ".0" : targetFramework[1];
dotNetCorePathFinder = new DotNetCorePathFinder(fileName, TargetFrameworkId, version); dotNetCorePathFinder = new DotNetCorePathFinder(fileName, TargetFrameworkId, version, this.loadedAssemblyReferences);
} }
file = dotNetCorePathFinder.TryResolveDotNetCore(name); file = dotNetCorePathFinder.TryResolveDotNetCore(name);
break; break;
@ -282,8 +280,10 @@ namespace ICSharpCode.ILSpy
file = Path.Combine(dir, name.Name + ".exe"); file = Path.Combine(dir, name.Name + ".exe");
} }
if (file != null) { if (file != null) {
loadedAssemblyReferences.AddMessage(fullName, MessageKind.Info, "Success - Loading from: " + file);
return assemblyList.OpenAssembly(file, true); return assemblyList.OpenAssembly(file, true);
} else { } else {
loadedAssemblyReferences.AddMessage(fullName, MessageKind.Error, "Could not find reference: " + fullName);
return null; return null;
} }
} }

16
ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs

@ -88,10 +88,22 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{ {
var loaded = parentAssembly.LoadedAssembly.LoadedAssemblyReferencesInfo.TryGetValue(r.FullName, out var info);
if (r.IsWindowsRuntime) { if (r.IsWindowsRuntime) {
language.WriteCommentLine(output, r.Name + " [WinRT]"); language.WriteCommentLine(output, r.Name + " [WinRT]" + (!loaded ? " (unresolved)" : ""));
} else { } else {
language.WriteCommentLine(output, r.FullName); language.WriteCommentLine(output, r.FullName + (!loaded ? " (unresolved)" : ""));
}
if (loaded) {
output.Indent();
language.WriteCommentLine(output, "Assembly reference loading information:");
if (info.HasErrors)
language.WriteCommentLine(output, "There were some problems during assembly reference load, see below for more information!");
foreach (var item in info.Messages) {
language.WriteCommentLine(output, $"{item.Item1}: {item.Item2}");
}
output.Unindent();
output.WriteLine();
} }
} }
} }

3
ILSpy/TreeNodes/ReferenceFolderTreeNode.cs

@ -61,7 +61,10 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{ {
language.WriteCommentLine(output, $"Detected Target-Framework-Id: {parentAssembly.LoadedAssembly.TargetFrameworkId}");
App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(EnsureLazyChildren)); App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(EnsureLazyChildren));
output.WriteLine();
language.WriteCommentLine(output, "Referenced assemblies (in metadata order):");
// Show metadata order of references // Show metadata order of references
foreach (var r in module.AssemblyReferences) foreach (var r in module.AssemblyReferences)
new AssemblyReferenceTreeNode(r, parentAssembly).Decompile(language, output, options); new AssemblyReferenceTreeNode(r, parentAssembly).Decompile(language, output, options);

Loading…
Cancel
Save