diff --git a/.gitignore b/.gitignore index e284b1638..18ce1cf70 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ _ReSharper*/ /ICSharpCode.Decompiler.Tests/TestCases/Correctness/*.exe /ICSharpCode.Decompiler.Tests/TestCases/Correctness/*.exe.config /ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec +multitargeting.props \ No newline at end of file diff --git a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj index 2b68ae535..1f7089137 100644 --- a/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj +++ b/ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj @@ -1,13 +1,17 @@  - net472 ILSpy.BamlDecompiler.Plugin 8.0 False 6488064 true + + + + net472 + full diff --git a/ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj b/ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj index 53d2c0940..0fe7e521e 100644 --- a/ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj +++ b/ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj @@ -2,13 +2,17 @@ - net472 ILSpy.ReadyToRun.Plugin 8.0 False en-US true + + + + net472 + full diff --git a/ILSpy/App.xaml.cs b/ILSpy/App.xaml.cs index 6541f453f..bc2e856fc 100644 --- a/ILSpy/App.xaml.cs +++ b/ILSpy/App.xaml.cs @@ -22,6 +22,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.Loader; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -35,6 +36,7 @@ using Microsoft.VisualStudio.Composition; using TomsToolbox.Wpf.Styles; + namespace ICSharpCode.ILSpy { /// @@ -85,8 +87,27 @@ namespace ICSharpCode.ILSpy ILSpyTraceListener.Install(); } + static Assembly ResolvePluginDependencies(AssemblyLoadContext context, AssemblyName assemblyName) + { +#if !NET472 + var rootPath = Path.GetDirectoryName(typeof(App).Assembly.Location); + var assemblyFileName = Path.Combine(rootPath, assemblyName.Name + ".dll"); + if (!File.Exists(assemblyFileName)) + return null; + return context.LoadFromAssemblyPath(assemblyFileName); +#else + throw new NotImplementedException(); +#endif + } + private static async Task InitializeMef() { +#if !NET472 + // Add custom logic for resolution of dependencies. + // This necessary because the AssemblyLoadContext.LoadFromAssemblyPath and related methods, + // do not automatically load dependencies. + AssemblyLoadContext.Default.Resolving += ResolvePluginDependencies; +#endif // Cannot show MessageBox here, because WPF would crash with a XamlParseException // Remember and show exceptions in text output, once MainWindow is properly initialized try @@ -98,7 +119,6 @@ namespace ICSharpCode.ILSpy var discovery = new AttributedPartDiscoveryV1(Resolver.DefaultInstance); var catalog = ComposableCatalog.Create(Resolver.DefaultInstance); var pluginDir = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName); -#if NET472 if (pluginDir != null) { foreach (var plugin in Directory.GetFiles(pluginDir, "*.Plugin.dll")) @@ -106,7 +126,11 @@ namespace ICSharpCode.ILSpy var name = Path.GetFileNameWithoutExtension(plugin); try { +#if NET472 var asm = Assembly.Load(name); +#else + var asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(plugin); +#endif var parts = await discovery.CreatePartsAsync(asm); catalog = catalog.AddParts(parts); } @@ -116,7 +140,6 @@ namespace ICSharpCode.ILSpy } } } -#endif // Add the built-in parts var createdParts = await discovery.CreatePartsAsync(Assembly.GetExecutingAssembly()); catalog = catalog.AddParts(createdParts); diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index dc2996195..03753f681 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -2,7 +2,6 @@ - net472 WinExe 9.0 False @@ -18,6 +17,11 @@ True ..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk + + + + net472 + full @@ -49,6 +53,7 @@ + diff --git a/ILSpy/StorePackageHelper.cs b/ILSpy/StorePackageHelper.cs index f7def8fac..99f7e24f2 100644 --- a/ILSpy/StorePackageHelper.cs +++ b/ILSpy/StorePackageHelper.cs @@ -9,16 +9,18 @@ namespace ICSharpCode.ILSpy get { #if NET472 return WindowsVersionHelper.HasPackageIdentity; -#endif +#else return false; +#endif } } public static string GetPackageFamilyName() { #if NET472 return WindowsVersionHelper.GetPackageFamilyName(); -#endif +#else return ""; +#endif } } } diff --git a/SharpTreeView/ICSharpCode.TreeView.csproj b/SharpTreeView/ICSharpCode.TreeView.csproj index 7501ea6d7..017bc286b 100644 --- a/SharpTreeView/ICSharpCode.TreeView.csproj +++ b/SharpTreeView/ICSharpCode.TreeView.csproj @@ -2,12 +2,16 @@ - net472 true False True ..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk + + + + net472 + full diff --git a/multitargeting.props.template b/multitargeting.props.template new file mode 100644 index 000000000..e196b6ad7 --- /dev/null +++ b/multitargeting.props.template @@ -0,0 +1,10 @@ + + + + + true + net472;net5.0-windows + + \ No newline at end of file