From 76816e22f1311a3b3665a1b88d803175a0ca27a4 Mon Sep 17 00:00:00 2001 From: Tyrrrz Date: Mon, 10 May 2021 21:10:42 +0300 Subject: [PATCH] Use Basic.Reference.Assemblies to simplify reference resolving for dynamic assemblies in tests Note: bumped `Microsoft.CodeAnalysis.CSharp` in test projects, but didn't touch the one in CliFx.Analyzers as it may have unintended side-effects. --- CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj | 5 +++-- CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs | 12 +++--------- CliFx.Tests/CliFx.Tests.csproj | 3 ++- CliFx.Tests/Utils/DynamicCommandBuilder.cs | 14 ++++---------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj b/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj index ab2e041..5db76b0 100644 --- a/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj +++ b/CliFx.Analyzers.Tests/CliFx.Analyzers.Tests.csproj @@ -13,11 +13,12 @@ + - - + + diff --git a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs index 7c34d6e..c9e3375 100644 --- a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs +++ b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; -using System.Reflection; using System.Text; +using Basic.Reference.Assemblies; using FluentAssertions.Execution; using FluentAssertions.Primitives; using Microsoft.CodeAnalysis; @@ -58,14 +58,8 @@ namespace CliFx.Analyzers.Tests.Utils var compilation = CSharpCompilation.Create( "CliFxTests_DynamicAssembly_" + Guid.NewGuid(), new[] {ast}, - new[] - { - MetadataReference.CreateFromFile(Assembly.Load("netstandard").Location), - MetadataReference.CreateFromFile(Assembly.Load("System.Runtime").Location), - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Console).Assembly.Location), - MetadataReference.CreateFromFile(typeof(ICommand).Assembly.Location) - }, + ReferenceAssemblies.Net50 + .Append(MetadataReference.CreateFromFile(typeof(ICommand).Assembly.Location)), // DLL to avoid having to define the Main() method new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) ); diff --git a/CliFx.Tests/CliFx.Tests.csproj b/CliFx.Tests/CliFx.Tests.csproj index b1618d3..1145f89 100644 --- a/CliFx.Tests/CliFx.Tests.csproj +++ b/CliFx.Tests/CliFx.Tests.csproj @@ -13,10 +13,11 @@ + - + diff --git a/CliFx.Tests/Utils/DynamicCommandBuilder.cs b/CliFx.Tests/Utils/DynamicCommandBuilder.cs index c7a78fb..391d64c 100644 --- a/CliFx.Tests/Utils/DynamicCommandBuilder.cs +++ b/CliFx.Tests/Utils/DynamicCommandBuilder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using Basic.Reference.Assemblies; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Text; @@ -60,16 +61,9 @@ namespace CliFx.Tests.Utils var compilation = CSharpCompilation.Create( "CliFxTests_DynamicAssembly_" + Guid.NewGuid(), new[] {ast}, - new[] - { - MetadataReference.CreateFromFile(Assembly.Load("netstandard").Location), - MetadataReference.CreateFromFile(Assembly.Load("System.Runtime").Location), - MetadataReference.CreateFromFile(typeof(object).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Console).Assembly.Location), - MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), - MetadataReference.CreateFromFile(typeof(DynamicCommandBuilder).Assembly.Location), - MetadataReference.CreateFromFile(typeof(ICommand).Assembly.Location) - }, + ReferenceAssemblies.Net50 + .Append(MetadataReference.CreateFromFile(typeof(ICommand).Assembly.Location)) + .Append(MetadataReference.CreateFromFile(typeof(DynamicCommandBuilder).Assembly.Location)), // DLL to avoid having to define the Main() method new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) );