Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/Particular.AnalyzerTesting/BaseCompilationTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace Particular.AnalyzerTesting;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
Expand All @@ -22,14 +25,24 @@ private protected BaseCompilationTest(string? outputAssemblyName = null)
{
this.outputAssemblyName = outputAssemblyName ?? "TestAssembly";

var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
foreach (var assembly in AssemblyLoadContext.Default.Assemblies)
{
if (!assembly.IsDynamic && !string.IsNullOrWhiteSpace(assembly.Location))
{
References.Add(MetadataReference.CreateFromFile(assembly.Location));
}
}

foreach (var assemblyPath in Directory.EnumerateFiles(RuntimeEnvironment.GetRuntimeDirectory(), "*.dll"))
{
using var stream = File.OpenRead(assemblyPath);
using var file = new PEReader(stream);

if (file.HasMetadata)
{
References.Add(MetadataReference.CreateFromFile(assemblyPath));
}
}
}

private protected TSelf Self => (TSelf)this;
Expand Down