diff --git a/ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs b/ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs
index 406838ad5..257f446c9 100644
--- a/ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs
+++ b/ICSharpCode.Decompiler.Console/IlspyCmdProgram.cs
@@ -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:
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:
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:
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;
diff --git a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
index bb3ca4fc7..64be74f0a 100644
--- a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
+++ b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
@@ -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
diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs
index 98a03476e..d05238198 100644
--- a/ILSpy/Languages/CSharpLanguage.cs
+++ b/ILSpy/Languages/CSharpLanguage.cs
@@ -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);
}
diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs
index d16bf7064..353f58c8e 100644
--- a/ILSpy/Properties/Resources.Designer.cs
+++ b/ILSpy/Properties/Resources.Designer.cs
@@ -522,6 +522,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Could not use SDK-style project format, because no compatible target-framework moniker was found..
+ ///
+ public static string CouldNotUseSdkStyleProjectFormat {
+ get {
+ return ResourceManager.GetString("CouldNotUseSdkStyleProjectFormat", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Create.
///
diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx
index 14cb244e3..66dc8e0ad 100644
--- a/ILSpy/Properties/Resources.resx
+++ b/ILSpy/Properties/Resources.resx
@@ -201,6 +201,9 @@ Are you sure you want to continue?
Copy FQ Name
+
+ Could not use SDK-style project format, because no compatible target-framework moniker was found.
+
Create
diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs
index a2e33eaa7..76c563e09 100644
--- a/ILSpy/TextView/DecompilerTextView.cs
+++ b/ILSpy/TextView/DecompilerTextView.cs
@@ -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
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 + "\""); });