1- using System . Collections . Immutable ;
1+ using System . Collections ;
2+ using System . Collections . Immutable ;
3+ using System . Net ;
4+ using System . Runtime . CompilerServices ;
25using Microsoft . CodeAnalysis ;
36using Microsoft . CodeAnalysis . Diagnostics ;
4- using Microsoft . CodeAnalysis . Testing ;
57using Microsoft . CodeAnalysis . Text ;
68
79namespace CSharpGuidelinesAnalyzer . Test . RoslynTestFramework ;
@@ -14,9 +16,8 @@ public sealed class AnalyzerTestContext
1416 private const OutputKind DefaultOutputKind = OutputKind . DynamicallyLinkedLibrary ;
1517 private const TestValidationMode DefaultTestValidationMode = TestValidationMode . AllowCompileWarnings ;
1618
17- private static readonly Lazy < ImmutableHashSet < MetadataReference > > DefaultReferencesLazy = new (
18- ( ) => ReferenceAssemblies . Net . Net60 . ResolveAsync ( null , CancellationToken . None ) . Result . ToImmutableHashSet ( ) ,
19- LazyThreadSafetyMode . ExecutionAndPublication ) ;
19+ private static readonly Lazy < ImmutableHashSet < MetadataReference > > DefaultReferencesLazy =
20+ new ( ResolveDefaultReferences , LazyThreadSafetyMode . ExecutionAndPublication ) ;
2021
2122 public string SourceCode { get ; }
2223 public IList < TextSpan > SourceSpans { get ; }
@@ -56,6 +57,26 @@ private AnalyzerTestContext(string sourceCode, IList<TextSpan> sourceSpans, stri
5657 }
5758#pragma warning restore AV1561 // Signature contains too many parameters
5859
60+ private static ImmutableHashSet < MetadataReference > ResolveDefaultReferences ( )
61+ {
62+ string assemblyPath = Path . GetDirectoryName ( typeof ( object ) . Assembly . Location ) ! ;
63+
64+ string [ ] assemblies =
65+ {
66+ typeof ( object ) . Assembly . Location , // System.Private.CoreLib.dll
67+ typeof ( BitArray ) . Assembly . Location , // System.Collections.dll
68+ typeof ( IImmutableList < > ) . Assembly . Location , // System.Collections.Immutable.dll
69+ typeof ( Enumerable ) . Assembly . Location , // System.Linq.dll
70+ typeof ( Queryable ) . Assembly . Location , // System.Linq.Queryable.dll
71+ typeof ( Console ) . Assembly . Location , // System.Console.dll
72+ typeof ( DynamicAttribute ) . Assembly . Location , // System.Linq.Expressions.dll
73+ typeof ( IPAddress ) . Assembly . Location , // System.Net.Primitives.dll
74+ Path . Combine ( assemblyPath , "System.Runtime.dll" )
75+ } ;
76+
77+ return assemblies . Select ( assembly => ( MetadataReference ) MetadataReference . CreateFromFile ( assembly ) ) . ToImmutableHashSet ( ) ;
78+ }
79+
5980 public AnalyzerTestContext WithCode ( string sourceCode , IList < TextSpan > sourceSpans )
6081 {
6182 FrameworkGuard . NotNull ( sourceCode , nameof ( sourceCode ) ) ;
0 commit comments