Browse Source

Make it easy to play with .NET 5 (#2355)

* Work on #2324 with code written for a PoC with Siegfried Pammer some time ago.

Trying it out: copy multitargeting.props.template to multitargeting.props

* Copy all files to the output folder (otherwise NuGet assemblies aren't there for net5.0 which is nasty for debugging, and publish doesn't pick them up either)
pull/2360/head
Christoph Wille 4 years ago committed by GitHub
parent
commit
1034eca9b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. 6
      ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj
  3. 6
      ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj
  4. 27
      ILSpy/App.xaml.cs
  5. 7
      ILSpy/ILSpy.csproj
  6. 6
      ILSpy/StorePackageHelper.cs
  7. 6
      SharpTreeView/ICSharpCode.TreeView.csproj
  8. 10
      multitargeting.props.template

1
.gitignore vendored

@ -18,3 +18,4 @@ _ReSharper*/ @@ -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

6
ILSpy.BamlDecompiler/ILSpy.BamlDecompiler.csproj

@ -1,13 +1,17 @@ @@ -1,13 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>ILSpy.BamlDecompiler.Plugin</AssemblyName>
<LangVersion>8.0</LangVersion>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<BaseAddress>6488064</BaseAddress>
<UseWpf>true</UseWpf>
</PropertyGroup>
<Import Project="..\multitargeting.props" Condition="Exists('..\multitargeting.props')" />
<PropertyGroup Condition="!Exists('..\multitargeting.props')">
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugType>full</DebugType>

6
ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj

@ -2,13 +2,17 @@ @@ -2,13 +2,17 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>ILSpy.ReadyToRun.Plugin</AssemblyName>
<LangVersion>8.0</LangVersion>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<NeutralResourcesLanguage>en-US</NeutralResourcesLanguage>
<UseWpf>true</UseWpf>
</PropertyGroup>
<Import Project="..\multitargeting.props" Condition="Exists('..\multitargeting.props')" />
<PropertyGroup Condition="!Exists('..\multitargeting.props')">
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugType>full</DebugType>

27
ILSpy/App.xaml.cs

@ -22,6 +22,7 @@ using System.Diagnostics; @@ -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; @@ -35,6 +36,7 @@ using Microsoft.VisualStudio.Composition;
using TomsToolbox.Wpf.Styles;
namespace ICSharpCode.ILSpy
{
/// <summary>
@ -85,8 +87,27 @@ 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 @@ -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 @@ -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 @@ -116,7 +140,6 @@ namespace ICSharpCode.ILSpy
}
}
}
#endif
// Add the built-in parts
var createdParts = await discovery.CreatePartsAsync(Assembly.GetExecutingAssembly());
catalog = catalog.AddParts(createdParts);

7
ILSpy/ILSpy.csproj

@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<OutputType>WinExe</OutputType>
<LangVersion>9.0</LangVersion>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
@ -18,6 +17,11 @@ @@ -18,6 +17,11 @@
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<Import Project="..\multitargeting.props" Condition="Exists('..\multitargeting.props')" />
<PropertyGroup Condition="!Exists('..\multitargeting.props')">
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugType>full</DebugType>
@ -49,6 +53,7 @@ @@ -49,6 +53,7 @@
<PackageReference Include="DataGridExtensions" Version="2.5.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.31" />
<PackageReference Include="TomsToolbox.Wpf.Styles" Version="2.4.3" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
</ItemGroup>
<ItemGroup>

6
ILSpy/StorePackageHelper.cs

@ -9,16 +9,18 @@ namespace ICSharpCode.ILSpy @@ -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
}
}
}

6
SharpTreeView/ICSharpCode.TreeView.csproj

@ -2,12 +2,16 @@ @@ -2,12 +2,16 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<UseWpf>true</UseWpf>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<Import Project="..\multitargeting.props" Condition="Exists('..\multitargeting.props')" />
<PropertyGroup Condition="!Exists('..\multitargeting.props')">
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugType>full</DebugType>

10
multitargeting.props.template

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copy this file to multitargeting.props and in global.json, change to framework 5.0.100
-->
<Project>
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<TargetFrameworks>net472;net5.0-windows</TargetFrameworks>
</PropertyGroup>
</Project>
Loading…
Cancel
Save