Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for loading specific nuget.config in ReferenceAssemblies #639

Merged
merged 2 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,6 @@ virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.LanguageIsSupported(strin
virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.NotEmpty<T>(string collectionName, System.Collections.Generic.IEnumerable<T> collection) -> void
virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.PushContext(string context) -> Microsoft.CodeAnalysis.Testing.IVerifier
virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.SequenceEqual<T>(System.Collections.Generic.IEnumerable<T> expected, System.Collections.Generic.IEnumerable<T> actual, System.Collections.Generic.IEqualityComparer<T> equalityComparer = null, string message = null) -> void
virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.True(bool assert, string message = null) -> void
virtual Microsoft.CodeAnalysis.Testing.DefaultVerifier.True(bool assert, string message = null) -> void
Microsoft.CodeAnalysis.Testing.ReferenceAssemblies.NuGetConfigFilePath.get -> string
Microsoft.CodeAnalysis.Testing.ReferenceAssemblies.WithNuGetConfigFilePath(string nugetConfigFilePath) -> Microsoft.CodeAnalysis.Testing.ReferenceAssemblies
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private ReferenceAssemblies(
ImmutableArray<string> assemblies,
ImmutableArray<string> facadeAssemblies,
ImmutableDictionary<string, ImmutableArray<string>> languageSpecificAssemblies,
ImmutableArray<PackageIdentity> packages)
ImmutableArray<PackageIdentity> packages,
string? nugetConfigFilePath)
{
TargetFramework = targetFramework;
AssemblyIdentityComparer = assemblyIdentityComparer;
Expand All @@ -81,6 +82,7 @@ private ReferenceAssemblies(
FacadeAssemblies = facadeAssemblies.IsDefault ? ImmutableArray<string>.Empty : facadeAssemblies;
LanguageSpecificAssemblies = languageSpecificAssemblies;
Packages = packages.IsDefault ? ImmutableArray<PackageIdentity>.Empty : packages;
NuGetConfigFilePath = nugetConfigFilePath;
}

public static ReferenceAssemblies Default
Expand Down Expand Up @@ -119,14 +121,16 @@ public static ReferenceAssemblies Default

public ImmutableArray<PackageIdentity> Packages { get; }

public string? NuGetConfigFilePath { get; }

public ReferenceAssemblies WithAssemblyIdentityComparer(AssemblyIdentityComparer assemblyIdentityComparer)
=> new ReferenceAssemblies(TargetFramework, assemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, FacadeAssemblies, LanguageSpecificAssemblies, Packages);
=> new ReferenceAssemblies(TargetFramework, assemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, FacadeAssemblies, LanguageSpecificAssemblies, Packages, NuGetConfigFilePath);

public ReferenceAssemblies WithAssemblies(ImmutableArray<string> assemblies)
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, assemblies, FacadeAssemblies, LanguageSpecificAssemblies, Packages);
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, assemblies, FacadeAssemblies, LanguageSpecificAssemblies, Packages, NuGetConfigFilePath);

public ReferenceAssemblies WithFacadeAssemblies(ImmutableArray<string> facadeAssemblies)
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, facadeAssemblies, LanguageSpecificAssemblies, Packages);
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, facadeAssemblies, LanguageSpecificAssemblies, Packages, NuGetConfigFilePath);

public ReferenceAssemblies AddAssemblies(ImmutableArray<string> assemblies)
=> WithAssemblies(Assemblies.AddRange(assemblies));
Expand All @@ -135,7 +139,7 @@ public ReferenceAssemblies AddFacadeAssemblies(ImmutableArray<string> facadeAsse
=> WithFacadeAssemblies(FacadeAssemblies.AddRange(facadeAssemblies));

public ReferenceAssemblies WithLanguageSpecificAssemblies(ImmutableDictionary<string, ImmutableArray<string>> languageSpecificAssemblies)
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, FacadeAssemblies, languageSpecificAssemblies, Packages);
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, FacadeAssemblies, languageSpecificAssemblies, Packages, NuGetConfigFilePath);

public ReferenceAssemblies WithLanguageSpecificAssemblies(string language, ImmutableArray<string> assemblies)
=> WithLanguageSpecificAssemblies(LanguageSpecificAssemblies.SetItem(language, assemblies));
Expand All @@ -151,11 +155,14 @@ public ReferenceAssemblies AddLanguageSpecificAssemblies(string language, Immuta
}

public ReferenceAssemblies WithPackages(ImmutableArray<PackageIdentity> packages)
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, FacadeAssemblies, LanguageSpecificAssemblies, packages);
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, FacadeAssemblies, LanguageSpecificAssemblies, packages, NuGetConfigFilePath);

public ReferenceAssemblies AddPackages(ImmutableArray<PackageIdentity> packages)
=> WithPackages(Packages.AddRange(packages));

public ReferenceAssemblies WithNuGetConfigFilePath(string nugetConfigFilePath)
sharwell marked this conversation as resolved.
Show resolved Hide resolved
=> new ReferenceAssemblies(TargetFramework, AssemblyIdentityComparer, ReferenceAssemblyPackage, ReferenceAssemblyPath, Assemblies, FacadeAssemblies, LanguageSpecificAssemblies, Packages, nugetConfigFilePath);

public async Task<ImmutableArray<MetadataReference>> ResolveAsync(string? language, CancellationToken cancellationToken)
{
if (language is object)
Expand Down Expand Up @@ -200,7 +207,7 @@ public async Task<ImmutableArray<MetadataReference>> ResolveAsync(string? langua
/// <seealso href="https://martinbjorkstrom.com/posts/2018-09-19-revisiting-nuget-client-libraries"/>
private async Task<ImmutableArray<MetadataReference>> ResolveCoreAsync(string language, CancellationToken cancellationToken)
{
var settings = Settings.LoadDefaultSettings(root: null);
var settings = string.IsNullOrEmpty(NuGetConfigFilePath) ? Settings.LoadDefaultSettings(root: null) : Settings.LoadSpecificSettings(root: null, NuGetConfigFilePath);
var sourceRepositoryProvider = new SourceRepositoryProvider(new PackageSourceProvider(settings), Repository.Provider.GetCoreV3());
var targetFramework = NuGetFramework.ParseFolder(TargetFramework);
var logger = NullLogger.Instance;
Expand Down