Skip to content

Commit e7d5edc

Browse files
committed
Revert ReferenceAssemblies package usage (blocking call hangs cibuild)
1 parent be8dc4f commit e7d5edc

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/CSharpGuidelinesAnalyzer/CSharpGuidelinesAnalyzer.Test/CSharpGuidelinesAnalyzer.Test.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<PackageReference Include="FluentAssertions" Version="6.6.0" />
1313
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" PrivateAssets="all" />
1414
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.1.0" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.1.1" />
1615
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
1716
<PackageReference Include="xunit" Version="2.4.1" />
1817
<PackageReference Include="xunit.runner.console" Version="2.4.1" PrivateAssets="all" />

src/CSharpGuidelinesAnalyzer/CSharpGuidelinesAnalyzer.Test/RoslynTestFramework/AnalyzerTestContext.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Collections.Immutable;
1+
using System.Collections;
2+
using System.Collections.Immutable;
3+
using System.Net;
4+
using System.Runtime.CompilerServices;
25
using Microsoft.CodeAnalysis;
36
using Microsoft.CodeAnalysis.Diagnostics;
4-
using Microsoft.CodeAnalysis.Testing;
57
using Microsoft.CodeAnalysis.Text;
68

79
namespace 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

Comments
 (0)