diff --git a/integrationtest/TargetProjects/NetCore/TargetProject/Constructs/Csharp1.cs b/integrationtest/TargetProjects/NetCore/TargetProject/Constructs/Csharp1.cs index 7fed4eb834..74badabf55 100644 --- a/integrationtest/TargetProjects/NetCore/TargetProject/Constructs/Csharp1.cs +++ b/integrationtest/TargetProjects/NetCore/TargetProject/Constructs/Csharp1.cs @@ -1,3 +1,5 @@ +extern alias TheLib; + using System.Linq; namespace TargetProject.Constructs; diff --git a/integrationtest/TargetProjects/NetCore/TargetProject/StrykerFeatures/UseAssert.cs b/integrationtest/TargetProjects/NetCore/TargetProject/StrykerFeatures/UseAssert.cs index b3659c250a..fecd937058 100644 --- a/integrationtest/TargetProjects/NetCore/TargetProject/StrykerFeatures/UseAssert.cs +++ b/integrationtest/TargetProjects/NetCore/TargetProject/StrykerFeatures/UseAssert.cs @@ -1,4 +1,7 @@ +extern alias TheLog; + using System.Diagnostics; +using TheLog::Serilog.Configuration; namespace TargetProject.StrykerFeatures; public class UseAssert @@ -7,6 +10,8 @@ public class UseAssert public void IncrementCounter() { + // this is only to check for alias support + var test = new BatchingOptions(); _counter++; Debug.Assert(_counter > 0, "Counter should be greater than 0"); } diff --git a/integrationtest/TargetProjects/NetCore/TargetProject/TargetProject.csproj b/integrationtest/TargetProjects/NetCore/TargetProject/TargetProject.csproj index 865c4f3ff7..8bfb6de81a 100644 --- a/integrationtest/TargetProjects/NetCore/TargetProject/TargetProject.csproj +++ b/integrationtest/TargetProjects/NetCore/TargetProject/TargetProject.csproj @@ -21,7 +21,9 @@ project reference path (it also ensures the import above was properly evaluated). --> - + + TheLib + <_Parameter1>$(AssemblyName).Tests @@ -29,6 +31,9 @@ + + TheLog + diff --git a/src/Stryker.Core/Stryker.Core.UnitTest/Compiling/CSharpCompilingProcessTests.cs b/src/Stryker.Core/Stryker.Core.UnitTest/Compiling/CSharpCompilingProcessTests.cs index e8ddef0db1..409dd9d5e3 100644 --- a/src/Stryker.Core/Stryker.Core.UnitTest/Compiling/CSharpCompilingProcessTests.cs +++ b/src/Stryker.Core/Stryker.Core.UnitTest/Compiling/CSharpCompilingProcessTests.cs @@ -75,8 +75,8 @@ public int Subtract(int first, int second) public void CompilingProcessTests_ShouldSupportPackageReferenceAliases() { var syntaxTree = CSharpSyntaxTree.ParseText(@" -extern alias TestAlias; -using TestAlias::System; +extern alias TheAlias; +using TheAlias::System; namespace ExampleProject { @@ -88,6 +88,10 @@ public int Subtract(int first, int second) } } }"); + var alias = new Dictionary>(); + var immutableArray = ImmutableArray.Create("TheAlias"); + alias[typeof(object).Assembly.Location]=immutableArray; + var input = new MutationTestInput() { SourceProjectInfo = new SourceProjectInfo @@ -101,21 +105,8 @@ public int Subtract(int first, int second) { "TargetFileName", "TargetFileName.dll" }, }, // add a reference to system so the example code can compile - references: new[] { typeof(object).Assembly.Location }, - packageReferences: new ReadOnlyDictionary>( - new Dictionary> - { - { - typeof(object).Assembly.GetName().Name, - new ReadOnlyDictionary( - new Dictionary - { - { "Aliases", "TestAlias" } - } - ) - } - } - ) + references: [typeof(object).Assembly.Location], + aliases: alias.ToImmutableDictionary() ).Object } }; diff --git a/src/Stryker.Core/Stryker.Core.UnitTest/TestHelper.cs b/src/Stryker.Core/Stryker.Core.UnitTest/TestHelper.cs index 76f535de3b..3b25eac836 100644 --- a/src/Stryker.Core/Stryker.Core.UnitTest/TestHelper.cs +++ b/src/Stryker.Core/Stryker.Core.UnitTest/TestHelper.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; using Buildalyzer; using Moq; @@ -15,7 +16,8 @@ public static Mock SetupProjectAnalyzerResult(Dictionary> packageReferences = null, string[] references = null, string[] preprocessorSymbols = null, - string[] analyzers = null + string[] analyzers = null, + ImmutableDictionary> aliases = null ) { var analyzerResultMock = new Mock(); @@ -67,7 +69,9 @@ public static Mock SetupProjectAnalyzerResult(Dictionary x.AnalyzerReferences).Returns(analyzers); } + aliases ??= ImmutableDictionary>.Empty; analyzerResultMock.Setup(x => x.Items).Returns(new Dictionary()); + analyzerResultMock.Setup(x => x.ReferenceAliases).Returns(aliases); return analyzerResultMock; } diff --git a/src/Stryker.Core/Stryker.Core/Initialisation/Buildalyzer/IAnalyzerResultExtensions.cs b/src/Stryker.Core/Stryker.Core/Initialisation/Buildalyzer/IAnalyzerResultExtensions.cs index 680e1817ca..c4cad977ef 100644 --- a/src/Stryker.Core/Stryker.Core/Initialisation/Buildalyzer/IAnalyzerResultExtensions.cs +++ b/src/Stryker.Core/Stryker.Core/Initialisation/Buildalyzer/IAnalyzerResultExtensions.cs @@ -107,28 +107,14 @@ public static IEnumerable LoadReferences(this IAnalyzerResult { foreach (var reference in analyzerResult.References) { - var referenceFileNameWithoutExtension = Path.GetFileNameWithoutExtension(reference); - string packageWithAlias = null; - if (analyzerResult.PackageReferences is not null) + if (!analyzerResult.ReferenceAliases.TryGetValue(reference, out var aliases)) { - // Check for any matching package reference with an alias using LINQ - packageWithAlias = analyzerResult.PackageReferences - .Where(pr => pr.Key == referenceFileNameWithoutExtension && pr.Value.ContainsKey("Aliases")) - .Select(pr => pr.Value["Aliases"]) - .FirstOrDefault(); - } - - if (packageWithAlias is not null) - { - // Return the reference with the alias - yield return MetadataReference.CreateFromFile(reference).WithAliases(new[] { packageWithAlias }); - } - else - { - // If no alias is found, return the reference without aliases - yield return MetadataReference.CreateFromFile(reference); + aliases = []; } + + // If no alias is found, return the reference without aliases + yield return MetadataReference.CreateFromFile(reference).WithAliases(aliases); } }