Browse Source

Fix #2893: Add option to disable automatic assembly loading.

This setting is honored by all functionality that triggers a decompilation run. It is ignored by features that load assemblies as their primary function. For example, using the "Load Dependencies" feature will still resolve and load assemblies from the file-system. The same happens when you double-click on an assembly reference in the tree view. It will be resolved and loaded.

Note that disabling automatic assembly load will cause the decompiler to potentially not be able to resolve types from references that have not been added manually and the quality of the decompiled code will be inferior as a result.
natural-type-lambdas-methods
Siegfried Pammer 2 years ago
parent
commit
1370b999fe
  1. 15
      ICSharpCode.Decompiler/DecompilerSettings.cs
  2. 2
      ILSpy/Commands/GeneratePdbContextMenuEntry.cs
  3. 6
      ILSpy/Languages/CSharpLanguage.cs
  4. 9
      ILSpy/Properties/Resources.Designer.cs
  5. 3
      ILSpy/Properties/Resources.resx
  6. 2
      ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs

15
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -1959,6 +1959,21 @@ namespace ICSharpCode.Decompiler @@ -1959,6 +1959,21 @@ namespace ICSharpCode.Decompiler
}
}
bool autoLoadAssemblyReferences = true;
[Category("DecompilerSettings.Other")]
[Description("DecompilerSettings.AutoLoadAssemblyReferences")]
public bool AutoLoadAssemblyReferences {
get { return autoLoadAssemblyReferences; }
set {
if (autoLoadAssemblyReferences != value)
{
autoLoadAssemblyReferences = value;
OnPropertyChanged();
}
}
}
#endregion
bool forStatement = true;

2
ILSpy/Commands/GeneratePdbContextMenuEntry.cs

@ -80,7 +80,7 @@ namespace ICSharpCode.ILSpy @@ -80,7 +80,7 @@ namespace ICSharpCode.ILSpy
{
try
{
var decompiler = new CSharpDecompiler(file, assembly.GetAssemblyResolver(), options.DecompilerSettings);
var decompiler = new CSharpDecompiler(file, assembly.GetAssemblyResolver(options.DecompilerSettings.AutoLoadAssemblyReferences), options.DecompilerSettings);
decompiler.CancellationToken = ct;
PortablePdbWriter.WritePdb(file, decompiler, options.DecompilerSettings, stream, progress: options.Progress);
}

6
ILSpy/Languages/CSharpLanguage.cs

@ -122,7 +122,7 @@ namespace ICSharpCode.ILSpy @@ -122,7 +122,7 @@ namespace ICSharpCode.ILSpy
CSharpDecompiler CreateDecompiler(PEFile module, DecompilationOptions options)
{
CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(), options.DecompilerSettings);
CSharpDecompiler decompiler = new CSharpDecompiler(module, module.GetAssemblyResolver(options.DecompilerSettings.AutoLoadAssemblyReferences), options.DecompilerSettings);
decompiler.CancellationToken = options.CancellationToken;
decompiler.DebugInfoProvider = module.GetDebugInfoOrNull();
while (decompiler.AstTransforms.Count > transformCount)
@ -416,7 +416,7 @@ namespace ICSharpCode.ILSpy @@ -416,7 +416,7 @@ namespace ICSharpCode.ILSpy
base.DecompileAssembly(assembly, output, options);
// don't automatically load additional assemblies when an assembly node is selected in the tree view
IAssemblyResolver assemblyResolver = assembly.GetAssemblyResolver(loadOnDemand: options.FullDecompilation);
IAssemblyResolver assemblyResolver = assembly.GetAssemblyResolver(loadOnDemand: options.FullDecompilation && options.DecompilerSettings.AutoLoadAssemblyReferences);
var typeSystem = new DecompilerTypeSystem(module, assemblyResolver, options.DecompilerSettings);
var globalType = typeSystem.MainModule.TypeDefinitions.FirstOrDefault();
if (globalType != null)
@ -507,7 +507,7 @@ namespace ICSharpCode.ILSpy @@ -507,7 +507,7 @@ namespace ICSharpCode.ILSpy
readonly DecompilationOptions options;
public ILSpyWholeProjectDecompiler(LoadedAssembly assembly, DecompilationOptions options)
: base(options.DecompilerSettings, assembly.GetAssemblyResolver(), assembly.GetAssemblyReferenceClassifier(options.DecompilerSettings.ApplyWindowsRuntimeProjections), assembly.GetDebugInfoOrNull())
: base(options.DecompilerSettings, assembly.GetAssemblyResolver(options.DecompilerSettings.AutoLoadAssemblyReferences, options.DecompilerSettings.ApplyWindowsRuntimeProjections), assembly.GetAssemblyReferenceClassifier(options.DecompilerSettings.ApplyWindowsRuntimeProjections), assembly.GetDebugInfoOrNull())
{
this.assembly = assembly;
this.options = options;

9
ILSpy/Properties/Resources.Designer.cs generated

@ -774,6 +774,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -774,6 +774,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Automatically load assembly references.
/// </summary>
public static string DecompilerSettings_AutoLoadAssemblyReferences {
get {
return ResourceManager.GetString("DecompilerSettings.AutoLoadAssemblyReferences", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User-defined checked operators.
/// </summary>

3
ILSpy/Properties/Resources.resx

@ -282,6 +282,9 @@ Are you sure you want to continue?</value> @@ -282,6 +282,9 @@ Are you sure you want to continue?</value>
<data name="DecompilerSettings.AsyncEnumerator" xml:space="preserve">
<value>Decompile async IAsyncEnumerator methods</value>
</data>
<data name="DecompilerSettings.AutoLoadAssemblyReferences" xml:space="preserve">
<value>Automatically load assembly references</value>
</data>
<data name="DecompilerSettings.CheckedOperators" xml:space="preserve">
<value>User-defined checked operators</value>
</data>

2
ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs

@ -75,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -75,7 +75,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
protected override void LoadChildren()
{
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver();
var resolver = parentAssembly.LoadedAssembly.GetAssemblyResolver(MainWindow.Instance.CurrentDecompilerSettings.AutoLoadAssemblyReferences);
var module = resolver.Resolve(r);
if (module != null)
{

Loading…
Cancel
Save