Browse Source

Fix exception when trying to export project for which no target-framework moniker was detected.

pull/2373/head
Siegfried Pammer 4 years ago
parent
commit
2a9a5237d1
  1. 11
      ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs
  2. 5
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
  3. 4
      ILSpy/Languages/CSharpLanguage.cs
  4. 9
      ILSpy/Properties/Resources.Designer.cs
  5. 3
      ILSpy/Properties/Resources.resx
  6. 8
      ILSpy/TextView/DecompilerTextView.cs

11
ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs

@ -135,12 +135,13 @@ Remarks: @@ -135,12 +135,13 @@ Remarks:
return 0;
}
DecompilerSettings GetSettings()
DecompilerSettings GetSettings(PEFile module)
{
return new DecompilerSettings(LanguageVersion) {
ThrowOnAssemblyResolveErrors = false,
RemoveDeadCode = RemoveDeadCode,
RemoveDeadStores = RemoveDeadStores
RemoveDeadStores = RemoveDeadStores,
UseSdkStyleProjectFormat = WholeProjectDecompiler.CanUseSdkStyleProjectFormat(module),
};
}
@ -151,7 +152,7 @@ Remarks: @@ -151,7 +152,7 @@ Remarks:
foreach (var path in ReferencePaths) {
resolver.AddSearchDirectory(path);
}
return new CSharpDecompiler(assemblyFileName, resolver, GetSettings()) {
return new CSharpDecompiler(assemblyFileName, resolver, GetSettings(module)) {
DebugInfoProvider = TryLoadPDB(module)
};
}
@ -188,7 +189,7 @@ Remarks: @@ -188,7 +189,7 @@ Remarks:
foreach (var path in ReferencePaths) {
resolver.AddSearchDirectory(path);
}
var decompiler = new WholeProjectDecompiler(GetSettings(), resolver, resolver, TryLoadPDB(module));
var decompiler = new WholeProjectDecompiler(GetSettings(module), resolver, resolver, TryLoadPDB(module));
decompiler.DecompileProject(module, outputDirectory);
return 0;
}
@ -220,7 +221,7 @@ Remarks: @@ -220,7 +221,7 @@ Remarks:
using (FileStream stream = new FileStream(pdbFileName, FileMode.OpenOrCreate, FileAccess.Write)) {
var decompiler = GetDecompiler(assemblyFileName);
PortablePdbWriter.WritePdb(module, decompiler, GetSettings(), stream);
PortablePdbWriter.WritePdb(module, decompiler, GetSettings(module), stream);
}
return 0;

5
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs

@ -625,6 +625,11 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -625,6 +625,11 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
return false;
}
}
public static bool CanUseSdkStyleProjectFormat(PEFile module)
{
return TargetServices.DetectTargetFramework(module).Moniker != null;
}
}
public readonly struct DecompilationProgress

4
ILSpy/Languages/CSharpLanguage.cs

@ -393,6 +393,10 @@ namespace ICSharpCode.ILSpy @@ -393,6 +393,10 @@ namespace ICSharpCode.ILSpy
}
if (options.FullDecompilation && options.SaveAsProjectDirectory != null)
{
if (!WholeProjectDecompiler.CanUseSdkStyleProjectFormat(module))
{
options.DecompilerSettings.UseSdkStyleProjectFormat = false;
}
var decompiler = new ILSpyWholeProjectDecompiler(assembly, options);
return decompiler.DecompileProject(module, options.SaveAsProjectDirectory, new TextOutputWriter(output), options.CancellationToken);
}

9
ILSpy/Properties/Resources.Designer.cs generated

@ -522,6 +522,15 @@ namespace ICSharpCode.ILSpy.Properties { @@ -522,6 +522,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Could not use SDK-style project format, because no compatible target-framework moniker was found..
/// </summary>
public static string CouldNotUseSdkStyleProjectFormat {
get {
return ResourceManager.GetString("CouldNotUseSdkStyleProjectFormat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Create.
/// </summary>

3
ILSpy/Properties/Resources.resx

@ -201,6 +201,9 @@ Are you sure you want to continue?</value> @@ -201,6 +201,9 @@ Are you sure you want to continue?</value>
<data name="CopyName" xml:space="preserve">
<value>Copy FQ Name</value>
</data>
<data name="CouldNotUseSdkStyleProjectFormat" xml:space="preserve">
<value>Could not use SDK-style project format, because no compatible target-framework moniker was found.</value>
</data>
<data name="Create" xml:space="preserve">
<value>Create</value>
</data>

8
ILSpy/TextView/DecompilerTextView.cs

@ -1075,6 +1075,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -1075,6 +1075,7 @@ namespace ICSharpCode.ILSpy.TextView
delegate {
try
{
bool originalProjectFormatSetting = context.Options.DecompilerSettings.UseSdkStyleProjectFormat;
context.Options.EscapeInvalidIdentifiers = true;
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@ -1101,11 +1102,16 @@ namespace ICSharpCode.ILSpy.TextView @@ -1101,11 +1102,16 @@ namespace ICSharpCode.ILSpy.TextView
if (context.Options.SaveAsProjectDirectory != null)
{
output.WriteLine();
if (context.Options.DecompilerSettings.UseSdkStyleProjectFormat)
bool useSdkStyleProjectFormat = context.Options.DecompilerSettings.UseSdkStyleProjectFormat;
if (useSdkStyleProjectFormat)
output.WriteLine(Properties.Resources.ProjectExportFormatSDKHint);
else
output.WriteLine(Properties.Resources.ProjectExportFormatNonSDKHint);
output.WriteLine(Properties.Resources.ProjectExportFormatChangeSettingHint);
if (originalProjectFormatSetting != useSdkStyleProjectFormat)
{
output.WriteLine(Properties.Resources.CouldNotUseSdkStyleProjectFormat);
}
}
output.WriteLine();
output.AddButton(null, Properties.Resources.OpenExplorer, delegate { Process.Start("explorer", "/select,\"" + fileName + "\""); });

Loading…
Cancel
Save