Skip to content

Commit

Permalink
Use the assembly resolver from the module definition
Browse files Browse the repository at this point in the history
Use the IAssemblyResolver provided by the module definition itself instead of the default resolver when reading the Costura template with Cecil so that assembly references are properly resolved for .NET Framework assemblies, even when running from a .NET Core runtime (which is exactly what is happening when running the `dotnet msbuild` command).

When using the default assembly resolver, bad assembly references would be added to a weaved .NET Framework assembly, for example `System.Private.CoreLib` would be added as an assembly reference, making the weaved executable crash at startup.

Fixes #694
  • Loading branch information
0xced committed Apr 19, 2021
1 parent 7943c90 commit 3a33f85
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/Costura.Fody.Tests/Helpers/WeavingHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Costura.Fody.Tests;
Expand All @@ -16,7 +15,6 @@ public static TestResult CreateIsolatedAssemblyCopy(string assemblyPath, string
Config = XElement.Parse(config),
References = string.Join(";", references.Select(r => Path.Combine(currentDirectory, r))),
ReferenceCopyLocalPaths = references.Select(r => Path.Combine(currentDirectory, r)).ToList(),
AssemblyResolver = new TestAssemblyResolver()
};

if (!Path.IsPathRooted(assemblyPath))
Expand Down
2 changes: 1 addition & 1 deletion src/Costura.Fody/AssemblyLoaderImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private void ImportAssemblyLoader(bool createTemporaryAssemblies)
{
var readerParameters = new ReaderParameters
{
AssemblyResolver = AssemblyResolver,
AssemblyResolver = ModuleDefinition.AssemblyResolver,
ReadSymbols = true,
SymbolReaderProvider = new PdbReaderProvider(),
SymbolStream = GetType().Assembly.GetManifestResourceStream("Costura.Template.pdb"),
Expand Down
3 changes: 0 additions & 3 deletions src/Costura.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using Fody;
using Mono.Cecil;

public partial class ModuleWeaver: BaseModuleWeaver
{
public IAssemblyResolver AssemblyResolver { get; set; }

public override void Execute()
{
//#if DEBUG
Expand Down

0 comments on commit 3a33f85

Please sign in to comment.