|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
3 | 3 |
|
| 4 | +#pragma warning disable SA1202 // Elements should be ordered by access - because field initializer depend on each other |
| 5 | + |
4 | 6 | using System.Collections.Immutable; |
5 | 7 | using Microsoft.CodeAnalysis.Testing; |
6 | 8 |
|
7 | 9 | internal static class ReferencesHelper |
8 | 10 | { |
| 11 | + private static readonly string NuGetConfigPath = FindNuGetConfigPath(); |
| 12 | + |
9 | 13 | public static readonly ReferenceAssemblies DefaultReferences = ReferenceAssemblies.Net.Net80 |
| 14 | + .WithNuGetConfigFilePath(NuGetConfigPath) |
10 | 15 | .WithPackages(ImmutableArray.Create( |
11 | 16 | new PackageIdentity("System.ComponentModel.Composition", "8.0.0"), |
12 | 17 | new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"), |
13 | 18 | new PackageIdentity("Microsoft.VisualStudio.Threading", "17.13.2"), |
14 | 19 | new PackageIdentity("Microsoft.VisualStudio.Validation", "17.8.8"))); |
| 20 | + |
| 21 | + private static string FindNuGetConfigPath() |
| 22 | + { |
| 23 | + string? path = AppContext.BaseDirectory; |
| 24 | + while (path is not null) |
| 25 | + { |
| 26 | + string candidate = Path.Combine(path, "nuget.config"); |
| 27 | + if (File.Exists(candidate)) |
| 28 | + { |
| 29 | + return candidate; |
| 30 | + } |
| 31 | + |
| 32 | + path = Path.GetDirectoryName(path); |
| 33 | + } |
| 34 | + |
| 35 | + throw new InvalidOperationException("Could not find NuGet.config by searching up from " + AppContext.BaseDirectory); |
| 36 | + } |
15 | 37 | } |
0 commit comments