Skip to content

Commit

Permalink
No cecil ref in fody (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 2, 2019
1 parent 7f4f425 commit 9236ca8
Show file tree
Hide file tree
Showing 49 changed files with 137 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>6.0.4-beta.1</Version>
<Version>6.0.4-beta.2</Version>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>8.0</LangVersion>
<NoWarn>CS1591;CS0618</NoWarn>
Expand Down
9 changes: 8 additions & 1 deletion Fody.sln
@@ -1,4 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29201.188
MinimumVisualStudioVersion = 16.0.29201.188
Expand Down Expand Up @@ -30,6 +31,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWeaver", "SampleWeaver\SampleWeaver.csproj", "{C07F5786-84DD-460C-A846-50311562790D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FodyHelpers.Tests", "FodyHelpers.Tests\FodyHelpers.Tests.csproj", "{68109B11-B125-47D2-A188-15D8793DEC6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +75,10 @@ Global
{C07F5786-84DD-460C-A846-50311562790D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C07F5786-84DD-460C-A846-50311562790D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C07F5786-84DD-460C-A846-50311562790D}.Release|Any CPU.Build.0 = Release|Any CPU
{68109B11-B125-47D2-A188-15D8793DEC6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68109B11-B125-47D2-A188-15D8793DEC6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68109B11-B125-47D2-A188-15D8793DEC6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68109B11-B125-47D2-A188-15D8793DEC6F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 0 additions & 1 deletion Fody/AssemblyPathValidator.cs
@@ -1,5 +1,4 @@
using System.IO;
using Fody;

public partial class Processor
{
Expand Down
3 changes: 1 addition & 2 deletions Fody/ConfigFileFinder/ConfigFileFinder.cs
@@ -1,5 +1,4 @@
using Fody;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
21 changes: 7 additions & 14 deletions Fody/Fody.csproj
Expand Up @@ -14,35 +14,28 @@
<NuspecProperties>configuration=$(Configuration);version=$(PackageVersion);authors=$(Authors);iconUrl=$(PackageIconUrl);projectUrl=$(PackageProjectUrl);description=$(Description);tags=$(PackageTags)</NuspecProperties>
</PropertyGroup>
</Target>
<ItemGroup>
<ProjectReference Include="..\FodyCommon\FodyCommon.csproj" PrivateAssets="All" />
<ProjectReference Include="..\FodyHelpers\FodyHelpers.csproj" PrivateAssets="All" />
<ProjectReference Include="..\FodyIsolated\FodyIsolated.csproj" PrivateAssets="All" />
<PackageReference Condition="$(Configuration)=='Release'" Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.3.0" PrivateAssets="All" />
<Reference Include="Mono.Cecil" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.dll" />
<Reference Include="Mono.Cecil.Pdb" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.Pdb.dll" />
<Reference Include="Mono.Cecil.Rocks" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.Rocks.dll" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'net472'">
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="Mono.Cecil" HintPath="..\Lib\Cecil\net40\Mono.Cecil.dll" />
<Reference Include="Mono.Cecil.Pdb" HintPath="..\Lib\Cecil\net40\Mono.Cecil.Pdb.dll" />
<Reference Include="Mono.Cecil.Rocks" HintPath="..\Lib\Cecil\net40\Mono.Cecil.Rocks.dll" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\FodyHelpers\Guard.cs" Link="Guard.cs" />
<Compile Include="..\FodyHelpers\MessageImportance.cs" Link="MessageImportance.cs" />
<Compile Include="..\FodyHelpers\MessageImportanceDefaults.cs" Link="MessageImportanceDefaults.cs" />
<Compile Include="..\FodyHelpers\Testing\PeVerifier.cs" Link="Verify\PeVerifier.cs" />
<Compile Include="..\FodyHelpers\Testing\SdkToolFinder.cs" Link="Verify\SdkToolFinder.cs" />
<ProjectReference Include="..\FodyCommon\FodyCommon.csproj" PrivateAssets="All" />
<PackageReference Condition="$(Configuration)=='Release'" Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
8 changes: 4 additions & 4 deletions Fody/Fody.nuspec
Expand Up @@ -15,11 +15,11 @@
</metadata>
<files>
<file src=".\bin\$configuration$\net472\Fody*.dll" target="netclassictask" />
<file src=".\bin\$configuration$\net472\Mono*.dll" target="netclassictask" />
<file src=".\bin\$configuration$\net472\Mono*.pdb" target="netclassictask" />
<file src="..\FodyIsolated\bin\$configuration$\net472\Fody*.dll" target="netclassictask" />
<file src="..\Lib\Cecil\net40\Mono*.*" target="netclassictask" />
<file src=".\bin\$configuration$\netstandard2.0\Fody*.dll" target="netstandardtask" />
<file src=".\bin\$configuration$\netstandard2.0\Mono*.dll" target="netstandardtask" />
<file src=".\bin\$configuration$\netstandard2.0\Mono*.pdb" target="netstandardtask" />
<file src="..\FodyIsolated\bin\$configuration$\netstandard2.0\Fody*.dll" target="netstandardtask" />
<file src="..\Lib\Cecil\netstandard2.0\Mono*.*" target="netstandardtask" />
<file src="Fody.targets" target="build" />
</files>
</package>
5 changes: 2 additions & 3 deletions Fody/Processor.cs
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Fody;

public partial class Processor
{
Expand Down Expand Up @@ -40,7 +39,7 @@ public virtual bool Execute()
{
var assembly = typeof(Processor).Assembly;

Logger.LogInfo($"Fody (version {FodyVersion.Version} @ {assembly.CodeBase}) Executing");
Logger.LogInfo($"Fody (version {typeof(Processor).Assembly.GetName().Version} @ {assembly.CodeBase}) Executing");

var stopwatch = Stopwatch.StartNew();

Expand Down Expand Up @@ -126,7 +125,7 @@ void ExecuteInOwnAssemblyLoadContext()
{
var loadContext = GetLoadContext();

using (innerWeaver = (IInnerWeaver)loadContext.CreateInstanceFromAndUnwrap())
using (innerWeaver = loadContext.CreateInstanceFromAndUnwrap())
{
innerWeaver.AssemblyFilePath = AssemblyFilePath;
innerWeaver.References = References;
Expand Down
1 change: 0 additions & 1 deletion Fody/ProjectPathFinder.cs
@@ -1,5 +1,4 @@
using System.IO;
using Fody;

public partial class Processor
{
Expand Down
1 change: 0 additions & 1 deletion Fody/SolutionPathValidator.cs
@@ -1,5 +1,4 @@
using System.IO;
using Fody;

public partial class Processor
{
Expand Down
9 changes: 9 additions & 0 deletions Fody/WeavingException.cs
@@ -0,0 +1,9 @@
using System;

class WeavingException : Exception
{
public WeavingException(string message)
: base(message)
{
}
}
1 change: 0 additions & 1 deletion Fody/XmlExtensions.cs
Expand Up @@ -2,7 +2,6 @@
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Fody;

public static class XmlExtensions
{
Expand Down
9 changes: 0 additions & 9 deletions FodyCommon/FodyCommon.csproj
Expand Up @@ -6,19 +6,10 @@
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework) == 'net472'">
<Reference Include="Mono.Cecil" HintPath="..\Lib\Cecil\net40\Mono.Cecil.dll" />
<Reference Include="Mono.Cecil.Pdb" HintPath="..\Lib\Cecil\net40\Mono.Cecil.Pdb.dll" />
<Reference Include="Mono.Cecil.Rocks" HintPath="..\Lib\Cecil\net40\Mono.Cecil.Rocks.dll" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'netstandard2.0'">
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<Reference Include="Mono.Cecil" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.dll" />
<Reference Include="Mono.Cecil.Pdb" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.Pdb.dll" />
<Reference Include="Mono.Cecil.Rocks" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.Rocks.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FodyHelpers\FodyHelpers.csproj" />
<PackageReference Condition="$(Configuration)=='Release'" Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion FodyCommon/IInnerWeaver.cs
Expand Up @@ -17,7 +17,9 @@ public interface IInnerWeaver : IDisposable
string ProjectFilePath { get; set; }
string DocumentationFilePath { get; set; }
DebugSymbolsType DebugSymbols { get; set; }

#if(NETSTANDARD)
IsolatedAssemblyLoadContext LoadContext { get; set; }
#endif
void Execute();
void Cancel();
}
34 changes: 29 additions & 5 deletions FodyCommon/IsolatedAssemblyLoadContext.cs
Expand Up @@ -15,10 +15,14 @@ public IsolatedAssemblyLoadContext()
appDomain = AppDomain.CreateDomain("Fody AppDomain", null, appDomainSetup);
}

public object CreateInstanceFromAndUnwrap()
public IInnerWeaver CreateInstanceFromAndUnwrap()
{
var assemblyFile = Path.Combine(AssemblyLocation.CurrentDirectory, "FodyIsolated.dll");
return appDomain.CreateInstanceFromAndUnwrap(assemblyFile, "InnerWeaver");
var innerWeaver = (IInnerWeaver)appDomain.CreateInstanceFromAndUnwrap(assemblyFile, "InnerWeaver");
#if(NETSTANDARD)
innerWeaver.LoadContext = this;
#endif
return innerWeaver;
}

public void Unload()
Expand All @@ -30,18 +34,38 @@ public void Unload()
using System.Reflection;
using System.Runtime.Loader;

public class IsolatedAssemblyLoadContext : AssemblyLoadContext
public class IsolatedAssemblyLoadContext :
AssemblyLoadContext
{
protected override Assembly Load(AssemblyName assemblyName)
{
if (assemblyName.Name == "FodyCommon")
{
return typeof(ILogger).Assembly;
}
var assemblyFile = Path.Combine(AssemblyLocation.CurrentDirectory, assemblyName.Name+".dll");

if (File.Exists(assemblyFile))
{
return LoadFromAssemblyPath(assemblyFile);
}

return null;
}

public object CreateInstanceFromAndUnwrap()
public IInnerWeaver CreateInstanceFromAndUnwrap()
{
var assemblyFile = Path.Combine(AssemblyLocation.CurrentDirectory, "FodyIsolated.dll");
var assembly = LoadFromAssemblyPath(assemblyFile);
return assembly.CreateInstance("InnerWeaver");
var innerWeaver = (IInnerWeaver)assembly.CreateInstance("InnerWeaver");
innerWeaver.LoadContext = this;
return innerWeaver;
}

public Assembly LoadNotLocked(string assemblyPath)
{
using var stream = File.OpenRead(assemblyPath);
return LoadFromStream(stream);
}

public void Unload()
Expand Down
9 changes: 9 additions & 0 deletions FodyCommon/WeavingException.cs
@@ -0,0 +1,9 @@
using System;

class WeavingException : Exception
{
public WeavingException(string message)
: base(message)
{
}
}
2 changes: 0 additions & 2 deletions FodyCommon/XDocumentEx.cs
Expand Up @@ -2,8 +2,6 @@
using System.Xml;
using System.Xml.Linq;

using Fody;

public static class XDocumentEx
{
public static XDocument Load(string path)
Expand Down
Expand Up @@ -39,7 +39,7 @@ public void Empty()
ApprovalTests.Approvals.Verify(exception.Message);
}

public ConfigReaderTests(ITestOutputHelper output) :
public ConfigReaderTests(ITestOutputHelper output) :
base(output)
{
}
Expand Down
42 changes: 42 additions & 0 deletions FodyHelpers.Tests/FodyHelpers.Tests.csproj
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netcoreapp2.2</TargetFrameworks>
<Optimize>False</Optimize>
<SignAssembly>true</SignAssembly>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Tests\ApprovalTestConfig.cs" Link="ApprovalTestConfig.cs" />
<Compile Include="..\Tests\RuntimeNamer.cs" Link="RuntimeNamer.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="ApprovalTests" Version="4.2.2" />
<PackageReference Include="ObjectApproval" Version="11.1.0" />
<PackageReference Include="Xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Xunit.ApprovalTests" Version="4.1.0" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<ProjectReference Include="..\DummyAssembly\DummyAssembly.csproj" />
<ProjectReference Include="..\FodyCommon\FodyCommon.csproj" />
<ProjectReference Include="..\FodyHelpers\FodyHelpers.csproj" />
<ProjectReference Include="..\FodyIsolated\FodyIsolated.csproj" />
<ProjectReference Include="..\SampleWeaver.Fody\SampleWeaver.Fody.csproj" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'net472'">
<Reference Include="Mono.Cecil" HintPath="..\Lib\Cecil\net40\Mono.Cecil.dll" />
<Reference Include="Mono.Cecil.Pdb" HintPath="..\Lib\Cecil\net40\Mono.Cecil.Pdb.dll" />
<Reference Include="Mono.Cecil.Rocks" HintPath="..\Lib\Cecil\net40\Mono.Cecil.Rocks.dll" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework) == 'netcoreapp2.2'">
<Reference Include="Mono.Cecil" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.dll" />
<Reference Include="Mono.Cecil.Pdb" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.Pdb.dll" />
<Reference Include="Mono.Cecil.Rocks" HintPath="..\Lib\Cecil\netstandard2.0\Mono.Cecil.Rocks.dll" />
</ItemGroup>
</Project>
File renamed without changes.
Expand Up @@ -11,7 +11,7 @@
public class PeVerifierTests :
XunitApprovalBase
{
string assemblyPath = "Tests.dll";
string assemblyPath = "FodyHelpers.Tests.dll";
[Fact]
public void StaticPathResolution()
{
Expand Down
File renamed without changes.
@@ -1,7 +1,7 @@
{
Messages: [
{
Text: '\tRemoving reference to \'Tests\'.',
Text: '\tRemoving reference to \'FodyHelpers.Tests\'.',
MessageImportance: 'Low'
}
],
Expand Down
@@ -1,7 +1,7 @@
{
Messages: [
{
Text: '\tRemoving reference to \'Tests\'.',
Text: '\tRemoving reference to \'FodyHelpers.Tests\'.',
MessageImportance: 'Low'
}
],
Expand Down
@@ -1,7 +1,7 @@
{
Messages: [
{
Text: '\tRemoving reference to \'Tests\'.',
Text: '\tRemoving reference to \'FodyHelpers.Tests\'.',
MessageImportance: 'Low'
}
],
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions FodyHelpers/AssemblyInfo.cs
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("FodyIsolated, PublicKey=0024000004800000940000000602000000240000525341310004000001000100F1DB6E31BB3DE8567F99174972F4AD7A91DB643505819CBAA82ED27A9BFA391E1BD72CBD4A1EB4C93F7122946B926A9672616F8A2BEF45DABB3C8AC655B365DFD5A1E7FE49E089D9E354499888BB49BDB4E9433C16A5EF61D52D3E39A590233659216EC85753981E4204D3B650DBED653B116DA2C30399A6F1A04196EA587BEC")]
[assembly:InternalsVisibleTo("FodyHelpers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100F1DB6E31BB3DE8567F99174972F4AD7A91DB643505819CBAA82ED27A9BFA391E1BD72CBD4A1EB4C93F7122946B926A9672616F8A2BEF45DABB3C8AC655B365DFD5A1E7FE49E089D9E354499888BB49BDB4E9433C16A5EF61D52D3E39A590233659216EC85753981E4204D3B650DBED653B116DA2C30399A6F1A04196EA587BEC")]
[assembly:InternalsVisibleTo("Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100F1DB6E31BB3DE8567F99174972F4AD7A91DB643505819CBAA82ED27A9BFA391E1BD72CBD4A1EB4C93F7122946B926A9672616F8A2BEF45DABB3C8AC655B365DFD5A1E7FE49E089D9E354499888BB49BDB4E9433C16A5EF61D52D3E39A590233659216EC85753981E4204D3B650DBED653B116DA2C30399A6F1A04196EA587BEC")]

0 comments on commit 9236ca8

Please sign in to comment.