Skip to content

Commit 50285f3

Browse files
authored
Merge pull request #1497 from microsoft/dev/andarno/fixAnalyzerTests
Fix analyzer tests to pull packages from our nuget.config feed
2 parents 7e4ea51 + 9c70c31 commit 50285f3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/Microsoft.VisualStudio.Threading.Analyzers.Tests/Helpers/ReferencesHelper.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
#pragma warning disable SA1202 // Elements should be ordered by access - because field initializer depend on each other
5+
6+
using System;
47
using System.Collections.Immutable;
8+
using System.IO;
59
using System.Net;
610

711
namespace Microsoft.VisualStudio.Threading.Analyzers.Tests;
812

913
internal static class ReferencesHelper
1014
{
15+
private static readonly string NuGetConfigPath = FindNuGetConfigPath();
16+
1117
#if NETFRAMEWORK
1218
public static ReferenceAssemblies DefaultReferences = ReferenceAssemblies.NetFramework.Net471.Default
1319
#elif NET8_0
1420
public static ReferenceAssemblies DefaultReferences = ReferenceAssemblies.Net.Net80
1521
#else
1622
#error Fix TFM conditions
1723
#endif
24+
.WithNuGetConfigFilePath(NuGetConfigPath)
1825
.WithPackages(ImmutableArray.Create(
1926
new PackageIdentity("System.Collections.Immutable", "6.0.0"),
2027
new PackageIdentity("System.Threading.Tasks.Extensions", "4.6.0"),
@@ -32,4 +39,21 @@ static ReferencesHelper()
3239
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
3340
#pragma warning restore RS0030 // Do not used banned APIs
3441
}
42+
43+
private static string FindNuGetConfigPath()
44+
{
45+
string? path = AppContext.BaseDirectory;
46+
while (path is not null)
47+
{
48+
string candidate = Path.Combine(path, "nuget.config");
49+
if (File.Exists(candidate))
50+
{
51+
return candidate;
52+
}
53+
54+
path = Path.GetDirectoryName(path);
55+
}
56+
57+
throw new InvalidOperationException("Could not find NuGet.config by searching up from " + AppContext.BaseDirectory);
58+
}
3559
}

0 commit comments

Comments
 (0)