From 9236ca84a1f660b067545bf3df5882fd0c0b7a9c Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sun, 3 Nov 2019 08:30:18 +1100 Subject: [PATCH] No cecil ref in fody (#755) --- Directory.Build.props | 2 +- Fody.sln | 9 +++- Fody/AssemblyPathValidator.cs | 1 - Fody/ConfigFileFinder/ConfigFileFinder.cs | 3 +- Fody/Fody.csproj | 21 ++++------ Fody/Fody.nuspec | 8 ++-- Fody/Processor.cs | 5 +-- Fody/ProjectPathFinder.cs | 1 - Fody/SolutionPathValidator.cs | 1 - Fody/WeavingException.cs | 9 ++++ Fody/XmlExtensions.cs | 1 - FodyCommon/FodyCommon.csproj | 9 ---- FodyCommon/IInnerWeaver.cs | 4 +- FodyCommon/IsolatedAssemblyLoadContext.cs | 34 ++++++++++++--- FodyCommon/WeavingException.cs | 9 ++++ FodyCommon/XDocumentEx.cs | 2 - .../ConfigReaderTests.Empty.approved.txt | 0 .../ConfigReaderTests.Whitespace.approved.txt | 0 .../ConfigReaderTests.cs | 2 +- FodyHelpers.Tests/FodyHelpers.Tests.csproj | 42 +++++++++++++++++++ ...VerifyMethod_netclassic_debug.approved.txt | 0 ...rifyMethod_netclassic_release.approved.txt | 0 ...ts.VerifyMethod_netcore_debug.approved.txt | 0 ....VerifyMethod_netcore_release.approved.txt | 0 ...Tests.Verify_netclassic_debug.approved.txt | 0 ...sts.Verify_netclassic_release.approved.txt | 0 ...asmTests.Verify_netcore_debug.approved.txt | 0 ...mTests.Verify_netcore_release.approved.txt | 0 .../IldasmTests.cs | 0 ...Invalid_assembly_should_throw.approved.txt | 0 ...VerifierTests.TrimLineNumbers.approved.txt | 0 .../PeVerifierTests.cs | 2 +- .../TargetWeaver.cs | 0 ...erConfigReadingTests.NoValues.approved.txt | 0 ...onfigReadingTests.UseExisting.approved.txt | 0 ...ConfigReadingTests.WithValues.approved.txt | 0 .../WeaverTestHelperTests.Run.approved.txt | 2 +- ...elperTests.WeaverUsingSymbols.approved.txt | 2 +- ...rTests.WithCustomAssemblyName.approved.txt | 2 +- .../WeaverTestHelperTests.cs | 0 .../WeaverUsingSymbols.cs | 0 FodyHelpers/AssemblyInfo.cs | 1 + FodyIsolated/AssemblyLoader.cs | 10 +++-- FodyIsolated/FodyIsolated.csproj | 1 + FodyIsolated/InnerWeaver.cs | 3 ++ Tests/{Fody => }/ApprovalTestConfig.cs | 0 .../ProjectWeaversReaderTests.cs | 6 +-- Tests/Fody/SolutionPathValidatorTests.cs | 7 +--- Tests/{FodyIsolated => }/RuntimeNamer.cs | 0 49 files changed, 137 insertions(+), 62 deletions(-) create mode 100644 Fody/WeavingException.cs create mode 100644 FodyCommon/WeavingException.cs rename {Tests/FodyHelpers => FodyHelpers.Tests}/ConfigReaderTests.Empty.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/ConfigReaderTests.Whitespace.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/ConfigReaderTests.cs (96%) create mode 100644 FodyHelpers.Tests/FodyHelpers.Tests.csproj rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.VerifyMethod_netclassic_debug.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.VerifyMethod_netclassic_release.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.VerifyMethod_netcore_debug.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.VerifyMethod_netcore_release.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.Verify_netclassic_debug.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.Verify_netclassic_release.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.Verify_netcore_debug.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.Verify_netcore_release.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/IldasmTests.cs (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/PeVerifierTests.Invalid_assembly_should_throw.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/PeVerifierTests.TrimLineNumbers.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/PeVerifierTests.cs (97%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/TargetWeaver.cs (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverConfigReadingTests.NoValues.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverConfigReadingTests.UseExisting.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverConfigReadingTests.WithValues.approved.txt (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverTestHelperTests.Run.approved.txt (74%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverTestHelperTests.WeaverUsingSymbols.approved.txt (74%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverTestHelperTests.WithCustomAssemblyName.approved.txt (73%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverTestHelperTests.cs (100%) rename {Tests/FodyHelpers => FodyHelpers.Tests}/WeaverUsingSymbols.cs (100%) rename Tests/{Fody => }/ApprovalTestConfig.cs (100%) rename Tests/{FodyIsolated => }/RuntimeNamer.cs (100%) diff --git a/Directory.Build.props b/Directory.Build.props index 8eb8f5ef5..d8f82dbc4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 6.0.4-beta.1 + 6.0.4-beta.2 true 8.0 CS1591;CS0618 diff --git a/Fody.sln b/Fody.sln index b3f8e92f7..6ffde8faa 100644 --- a/Fody.sln +++ b/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 @@ -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 @@ -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 diff --git a/Fody/AssemblyPathValidator.cs b/Fody/AssemblyPathValidator.cs index 38bb50ae9..e0b7b94e4 100644 --- a/Fody/AssemblyPathValidator.cs +++ b/Fody/AssemblyPathValidator.cs @@ -1,5 +1,4 @@ using System.IO; -using Fody; public partial class Processor { diff --git a/Fody/ConfigFileFinder/ConfigFileFinder.cs b/Fody/ConfigFileFinder/ConfigFileFinder.cs index 2bd25cdcd..1efee8ef6 100644 --- a/Fody/ConfigFileFinder/ConfigFileFinder.cs +++ b/Fody/ConfigFileFinder/ConfigFileFinder.cs @@ -1,5 +1,4 @@ -using Fody; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/Fody/Fody.csproj b/Fody/Fody.csproj index f1ba150ee..d3ee2e7f0 100644 --- a/Fody/Fody.csproj +++ b/Fody/Fody.csproj @@ -14,35 +14,28 @@ configuration=$(Configuration);version=$(PackageVersion);authors=$(Authors);iconUrl=$(PackageIconUrl);projectUrl=$(PackageProjectUrl);description=$(Description);tags=$(PackageTags) - - - - - - - - - - - - + + + + + + + True True Resources.resx - - ResXFileCodeGenerator Resources.Designer.cs diff --git a/Fody/Fody.nuspec b/Fody/Fody.nuspec index 15da1b07c..4189c15dc 100644 --- a/Fody/Fody.nuspec +++ b/Fody/Fody.nuspec @@ -15,11 +15,11 @@ - - + + - - + + \ No newline at end of file diff --git a/Fody/Processor.cs b/Fody/Processor.cs index 9d1ccb0fa..7e6c2cf3a 100644 --- a/Fody/Processor.cs +++ b/Fody/Processor.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Fody; public partial class Processor { @@ -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(); @@ -126,7 +125,7 @@ void ExecuteInOwnAssemblyLoadContext() { var loadContext = GetLoadContext(); - using (innerWeaver = (IInnerWeaver)loadContext.CreateInstanceFromAndUnwrap()) + using (innerWeaver = loadContext.CreateInstanceFromAndUnwrap()) { innerWeaver.AssemblyFilePath = AssemblyFilePath; innerWeaver.References = References; diff --git a/Fody/ProjectPathFinder.cs b/Fody/ProjectPathFinder.cs index 552056003..9e5bea141 100644 --- a/Fody/ProjectPathFinder.cs +++ b/Fody/ProjectPathFinder.cs @@ -1,5 +1,4 @@ using System.IO; -using Fody; public partial class Processor { diff --git a/Fody/SolutionPathValidator.cs b/Fody/SolutionPathValidator.cs index 590015f73..7d0ffb046 100644 --- a/Fody/SolutionPathValidator.cs +++ b/Fody/SolutionPathValidator.cs @@ -1,5 +1,4 @@ using System.IO; -using Fody; public partial class Processor { diff --git a/Fody/WeavingException.cs b/Fody/WeavingException.cs new file mode 100644 index 000000000..acfb3beb8 --- /dev/null +++ b/Fody/WeavingException.cs @@ -0,0 +1,9 @@ +using System; + +class WeavingException : Exception +{ + public WeavingException(string message) + : base(message) + { + } +} \ No newline at end of file diff --git a/Fody/XmlExtensions.cs b/Fody/XmlExtensions.cs index adf66591f..d7c767837 100644 --- a/Fody/XmlExtensions.cs +++ b/Fody/XmlExtensions.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Xml; using System.Xml.Linq; -using Fody; public static class XmlExtensions { diff --git a/FodyCommon/FodyCommon.csproj b/FodyCommon/FodyCommon.csproj index 170a7e8e3..3b4059e71 100644 --- a/FodyCommon/FodyCommon.csproj +++ b/FodyCommon/FodyCommon.csproj @@ -6,19 +6,10 @@ embedded true - - - - - - - - - \ No newline at end of file diff --git a/FodyCommon/IInnerWeaver.cs b/FodyCommon/IInnerWeaver.cs index 248d1dcfd..4773a0d1d 100644 --- a/FodyCommon/IInnerWeaver.cs +++ b/FodyCommon/IInnerWeaver.cs @@ -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(); } \ No newline at end of file diff --git a/FodyCommon/IsolatedAssemblyLoadContext.cs b/FodyCommon/IsolatedAssemblyLoadContext.cs index 6fc6fb7ab..136bdb16e 100644 --- a/FodyCommon/IsolatedAssemblyLoadContext.cs +++ b/FodyCommon/IsolatedAssemblyLoadContext.cs @@ -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() @@ -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() diff --git a/FodyCommon/WeavingException.cs b/FodyCommon/WeavingException.cs new file mode 100644 index 000000000..acfb3beb8 --- /dev/null +++ b/FodyCommon/WeavingException.cs @@ -0,0 +1,9 @@ +using System; + +class WeavingException : Exception +{ + public WeavingException(string message) + : base(message) + { + } +} \ No newline at end of file diff --git a/FodyCommon/XDocumentEx.cs b/FodyCommon/XDocumentEx.cs index 35c31d5e7..4d45284f3 100644 --- a/FodyCommon/XDocumentEx.cs +++ b/FodyCommon/XDocumentEx.cs @@ -2,8 +2,6 @@ using System.Xml; using System.Xml.Linq; -using Fody; - public static class XDocumentEx { public static XDocument Load(string path) diff --git a/Tests/FodyHelpers/ConfigReaderTests.Empty.approved.txt b/FodyHelpers.Tests/ConfigReaderTests.Empty.approved.txt similarity index 100% rename from Tests/FodyHelpers/ConfigReaderTests.Empty.approved.txt rename to FodyHelpers.Tests/ConfigReaderTests.Empty.approved.txt diff --git a/Tests/FodyHelpers/ConfigReaderTests.Whitespace.approved.txt b/FodyHelpers.Tests/ConfigReaderTests.Whitespace.approved.txt similarity index 100% rename from Tests/FodyHelpers/ConfigReaderTests.Whitespace.approved.txt rename to FodyHelpers.Tests/ConfigReaderTests.Whitespace.approved.txt diff --git a/Tests/FodyHelpers/ConfigReaderTests.cs b/FodyHelpers.Tests/ConfigReaderTests.cs similarity index 96% rename from Tests/FodyHelpers/ConfigReaderTests.cs rename to FodyHelpers.Tests/ConfigReaderTests.cs index 9e1165710..c5c69c93e 100644 --- a/Tests/FodyHelpers/ConfigReaderTests.cs +++ b/FodyHelpers.Tests/ConfigReaderTests.cs @@ -39,7 +39,7 @@ public void Empty() ApprovalTests.Approvals.Verify(exception.Message); } - public ConfigReaderTests(ITestOutputHelper output) : + public ConfigReaderTests(ITestOutputHelper output) : base(output) { } diff --git a/FodyHelpers.Tests/FodyHelpers.Tests.csproj b/FodyHelpers.Tests/FodyHelpers.Tests.csproj new file mode 100644 index 000000000..5f7e88a91 --- /dev/null +++ b/FodyHelpers.Tests/FodyHelpers.Tests.csproj @@ -0,0 +1,42 @@ + + + + net472;netcoreapp2.2 + False + true + false + full + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/FodyHelpers/IldasmTests.VerifyMethod_netclassic_debug.approved.txt b/FodyHelpers.Tests/IldasmTests.VerifyMethod_netclassic_debug.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.VerifyMethod_netclassic_debug.approved.txt rename to FodyHelpers.Tests/IldasmTests.VerifyMethod_netclassic_debug.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.VerifyMethod_netclassic_release.approved.txt b/FodyHelpers.Tests/IldasmTests.VerifyMethod_netclassic_release.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.VerifyMethod_netclassic_release.approved.txt rename to FodyHelpers.Tests/IldasmTests.VerifyMethod_netclassic_release.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.VerifyMethod_netcore_debug.approved.txt b/FodyHelpers.Tests/IldasmTests.VerifyMethod_netcore_debug.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.VerifyMethod_netcore_debug.approved.txt rename to FodyHelpers.Tests/IldasmTests.VerifyMethod_netcore_debug.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.VerifyMethod_netcore_release.approved.txt b/FodyHelpers.Tests/IldasmTests.VerifyMethod_netcore_release.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.VerifyMethod_netcore_release.approved.txt rename to FodyHelpers.Tests/IldasmTests.VerifyMethod_netcore_release.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.Verify_netclassic_debug.approved.txt b/FodyHelpers.Tests/IldasmTests.Verify_netclassic_debug.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.Verify_netclassic_debug.approved.txt rename to FodyHelpers.Tests/IldasmTests.Verify_netclassic_debug.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.Verify_netclassic_release.approved.txt b/FodyHelpers.Tests/IldasmTests.Verify_netclassic_release.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.Verify_netclassic_release.approved.txt rename to FodyHelpers.Tests/IldasmTests.Verify_netclassic_release.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.Verify_netcore_debug.approved.txt b/FodyHelpers.Tests/IldasmTests.Verify_netcore_debug.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.Verify_netcore_debug.approved.txt rename to FodyHelpers.Tests/IldasmTests.Verify_netcore_debug.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.Verify_netcore_release.approved.txt b/FodyHelpers.Tests/IldasmTests.Verify_netcore_release.approved.txt similarity index 100% rename from Tests/FodyHelpers/IldasmTests.Verify_netcore_release.approved.txt rename to FodyHelpers.Tests/IldasmTests.Verify_netcore_release.approved.txt diff --git a/Tests/FodyHelpers/IldasmTests.cs b/FodyHelpers.Tests/IldasmTests.cs similarity index 100% rename from Tests/FodyHelpers/IldasmTests.cs rename to FodyHelpers.Tests/IldasmTests.cs diff --git a/Tests/FodyHelpers/PeVerifierTests.Invalid_assembly_should_throw.approved.txt b/FodyHelpers.Tests/PeVerifierTests.Invalid_assembly_should_throw.approved.txt similarity index 100% rename from Tests/FodyHelpers/PeVerifierTests.Invalid_assembly_should_throw.approved.txt rename to FodyHelpers.Tests/PeVerifierTests.Invalid_assembly_should_throw.approved.txt diff --git a/Tests/FodyHelpers/PeVerifierTests.TrimLineNumbers.approved.txt b/FodyHelpers.Tests/PeVerifierTests.TrimLineNumbers.approved.txt similarity index 100% rename from Tests/FodyHelpers/PeVerifierTests.TrimLineNumbers.approved.txt rename to FodyHelpers.Tests/PeVerifierTests.TrimLineNumbers.approved.txt diff --git a/Tests/FodyHelpers/PeVerifierTests.cs b/FodyHelpers.Tests/PeVerifierTests.cs similarity index 97% rename from Tests/FodyHelpers/PeVerifierTests.cs rename to FodyHelpers.Tests/PeVerifierTests.cs index a3d819ebe..ca7163384 100644 --- a/Tests/FodyHelpers/PeVerifierTests.cs +++ b/FodyHelpers.Tests/PeVerifierTests.cs @@ -11,7 +11,7 @@ public class PeVerifierTests : XunitApprovalBase { - string assemblyPath = "Tests.dll"; + string assemblyPath = "FodyHelpers.Tests.dll"; [Fact] public void StaticPathResolution() { diff --git a/Tests/FodyHelpers/TargetWeaver.cs b/FodyHelpers.Tests/TargetWeaver.cs similarity index 100% rename from Tests/FodyHelpers/TargetWeaver.cs rename to FodyHelpers.Tests/TargetWeaver.cs diff --git a/Tests/FodyHelpers/WeaverConfigReadingTests.NoValues.approved.txt b/FodyHelpers.Tests/WeaverConfigReadingTests.NoValues.approved.txt similarity index 100% rename from Tests/FodyHelpers/WeaverConfigReadingTests.NoValues.approved.txt rename to FodyHelpers.Tests/WeaverConfigReadingTests.NoValues.approved.txt diff --git a/Tests/FodyHelpers/WeaverConfigReadingTests.UseExisting.approved.txt b/FodyHelpers.Tests/WeaverConfigReadingTests.UseExisting.approved.txt similarity index 100% rename from Tests/FodyHelpers/WeaverConfigReadingTests.UseExisting.approved.txt rename to FodyHelpers.Tests/WeaverConfigReadingTests.UseExisting.approved.txt diff --git a/Tests/FodyHelpers/WeaverConfigReadingTests.WithValues.approved.txt b/FodyHelpers.Tests/WeaverConfigReadingTests.WithValues.approved.txt similarity index 100% rename from Tests/FodyHelpers/WeaverConfigReadingTests.WithValues.approved.txt rename to FodyHelpers.Tests/WeaverConfigReadingTests.WithValues.approved.txt diff --git a/Tests/FodyHelpers/WeaverTestHelperTests.Run.approved.txt b/FodyHelpers.Tests/WeaverTestHelperTests.Run.approved.txt similarity index 74% rename from Tests/FodyHelpers/WeaverTestHelperTests.Run.approved.txt rename to FodyHelpers.Tests/WeaverTestHelperTests.Run.approved.txt index 2a934bac1..8636720b0 100644 --- a/Tests/FodyHelpers/WeaverTestHelperTests.Run.approved.txt +++ b/FodyHelpers.Tests/WeaverTestHelperTests.Run.approved.txt @@ -1,7 +1,7 @@ { Messages: [ { - Text: '\tRemoving reference to \'Tests\'.', + Text: '\tRemoving reference to \'FodyHelpers.Tests\'.', MessageImportance: 'Low' } ], diff --git a/Tests/FodyHelpers/WeaverTestHelperTests.WeaverUsingSymbols.approved.txt b/FodyHelpers.Tests/WeaverTestHelperTests.WeaverUsingSymbols.approved.txt similarity index 74% rename from Tests/FodyHelpers/WeaverTestHelperTests.WeaverUsingSymbols.approved.txt rename to FodyHelpers.Tests/WeaverTestHelperTests.WeaverUsingSymbols.approved.txt index 2a934bac1..8636720b0 100644 --- a/Tests/FodyHelpers/WeaverTestHelperTests.WeaverUsingSymbols.approved.txt +++ b/FodyHelpers.Tests/WeaverTestHelperTests.WeaverUsingSymbols.approved.txt @@ -1,7 +1,7 @@ { Messages: [ { - Text: '\tRemoving reference to \'Tests\'.', + Text: '\tRemoving reference to \'FodyHelpers.Tests\'.', MessageImportance: 'Low' } ], diff --git a/Tests/FodyHelpers/WeaverTestHelperTests.WithCustomAssemblyName.approved.txt b/FodyHelpers.Tests/WeaverTestHelperTests.WithCustomAssemblyName.approved.txt similarity index 73% rename from Tests/FodyHelpers/WeaverTestHelperTests.WithCustomAssemblyName.approved.txt rename to FodyHelpers.Tests/WeaverTestHelperTests.WithCustomAssemblyName.approved.txt index 175861260..c1f06c618 100644 --- a/Tests/FodyHelpers/WeaverTestHelperTests.WithCustomAssemblyName.approved.txt +++ b/FodyHelpers.Tests/WeaverTestHelperTests.WithCustomAssemblyName.approved.txt @@ -1,7 +1,7 @@ { Messages: [ { - Text: '\tRemoving reference to \'Tests\'.', + Text: '\tRemoving reference to \'FodyHelpers.Tests\'.', MessageImportance: 'Low' } ], diff --git a/Tests/FodyHelpers/WeaverTestHelperTests.cs b/FodyHelpers.Tests/WeaverTestHelperTests.cs similarity index 100% rename from Tests/FodyHelpers/WeaverTestHelperTests.cs rename to FodyHelpers.Tests/WeaverTestHelperTests.cs diff --git a/Tests/FodyHelpers/WeaverUsingSymbols.cs b/FodyHelpers.Tests/WeaverUsingSymbols.cs similarity index 100% rename from Tests/FodyHelpers/WeaverUsingSymbols.cs rename to FodyHelpers.Tests/WeaverUsingSymbols.cs diff --git a/FodyHelpers/AssemblyInfo.cs b/FodyHelpers/AssemblyInfo.cs index ca45685ea..604498941 100644 --- a/FodyHelpers/AssemblyInfo.cs +++ b/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")] \ No newline at end of file diff --git a/FodyIsolated/AssemblyLoader.cs b/FodyIsolated/AssemblyLoader.cs index 890814a17..4a978ab6f 100644 --- a/FodyIsolated/AssemblyLoader.cs +++ b/FodyIsolated/AssemblyLoader.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Reflection; public partial class InnerWeaver @@ -14,13 +13,18 @@ public Assembly LoadWeaverAssembly(string assemblyPath) Logger.LogDebug($" Loading '{assemblyPath}' from cache."); return assembly; } + Logger.LogDebug($" Loading '{assemblyPath}' from disk."); return assemblies[assemblyPath] = LoadFromFile(assemblyPath); } - static Assembly LoadFromFile(string assemblyPath) + Assembly LoadFromFile(string assemblyPath) { - var rawAssembly = File.ReadAllBytes(assemblyPath); + #if(NETSTANDARD) + return LoadContext.LoadNotLocked(assemblyPath); + #else + var rawAssembly = System.IO.File.ReadAllBytes(assemblyPath); return Assembly.Load(rawAssembly); + #endif } } \ No newline at end of file diff --git a/FodyIsolated/FodyIsolated.csproj b/FodyIsolated/FodyIsolated.csproj index f41467408..975c4e36d 100644 --- a/FodyIsolated/FodyIsolated.csproj +++ b/FodyIsolated/FodyIsolated.csproj @@ -5,6 +5,7 @@ $(SolutionDir)Key.snk embedded true + False diff --git a/FodyIsolated/InnerWeaver.cs b/FodyIsolated/InnerWeaver.cs index c311f9028..00999276a 100644 --- a/FodyIsolated/InnerWeaver.cs +++ b/FodyIsolated/InnerWeaver.cs @@ -32,6 +32,9 @@ public partial class InnerWeaver : public List ReferenceCopyLocalPaths { get; set; } public List DefineConstants { get; set; } public DebugSymbolsType DebugSymbols { get; set; } + #if (NETSTANDARD) + public IsolatedAssemblyLoadContext LoadContext { get; set; } + #endif bool cancelRequested; List weaverInstances = new List(); Action cancelDelegate; diff --git a/Tests/Fody/ApprovalTestConfig.cs b/Tests/ApprovalTestConfig.cs similarity index 100% rename from Tests/Fody/ApprovalTestConfig.cs rename to Tests/ApprovalTestConfig.cs diff --git a/Tests/Fody/ProjectWeaversReaderTests/ProjectWeaversReaderTests.cs b/Tests/Fody/ProjectWeaversReaderTests/ProjectWeaversReaderTests.cs index 231efc559..2c5922cac 100644 --- a/Tests/Fody/ProjectWeaversReaderTests/ProjectWeaversReaderTests.cs +++ b/Tests/Fody/ProjectWeaversReaderTests/ProjectWeaversReaderTests.cs @@ -1,5 +1,5 @@ +using System; using ApprovalTests; -using Fody; using Xunit; using Xunit.Abstractions; @@ -11,11 +11,11 @@ public void Invalid() { var path = @"Fody\ProjectWeaversReaderTests\Invalid.txt"; - var exception = Assert.Throws(() => XDocumentEx.Load(path)); + var exception = Assert.ThrowsAny(() => XDocumentEx.Load(path)); Approvals.Verify(exception.Message); } - public ProjectWeaversReaderTests(ITestOutputHelper output) : + public ProjectWeaversReaderTests(ITestOutputHelper output) : base(output) { } diff --git a/Tests/Fody/SolutionPathValidatorTests.cs b/Tests/Fody/SolutionPathValidatorTests.cs index df60490f4..3b0618a77 100644 --- a/Tests/Fody/SolutionPathValidatorTests.cs +++ b/Tests/Fody/SolutionPathValidatorTests.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using Fody; using Xunit; using Xunit.Abstractions; @@ -23,7 +22,7 @@ public void Valid() [Fact] public void InValid() { - Action paramName = () => + Action action = () => { var processor = new Processor { @@ -31,9 +30,7 @@ public void InValid() }; processor.ValidateSolutionPath(); }; -#pragma warning disable xUnit2015 // Do not use typeof expression to check the exception type - var exception = Assert.Throws(typeof(WeavingException), paramName); -#pragma warning restore xUnit2015 // Do not use typeof expression to check the exception type + var exception = Assert.ThrowsAny(action); Assert.Equal($"SolutionDir '{Path.GetFullPath("aString")}' does not exist.", exception.Message); } diff --git a/Tests/FodyIsolated/RuntimeNamer.cs b/Tests/RuntimeNamer.cs similarity index 100% rename from Tests/FodyIsolated/RuntimeNamer.cs rename to Tests/RuntimeNamer.cs