Minor API cleanup
- Make ProjectContextBuilder a fluent API - Rename ResolveRepositoryPath to ResolvePackagesPath
This commit is contained in:
parent
2a37430053
commit
c83f58d566
3 changed files with 72 additions and 20 deletions
|
@ -74,11 +74,10 @@ namespace Microsoft.Extensions.ProjectModel
|
|||
projectPath = Path.GetDirectoryName(projectPath);
|
||||
}
|
||||
return new ProjectContextBuilder()
|
||||
{
|
||||
ProjectDirectory = projectPath,
|
||||
TargetFramework = framework,
|
||||
RuntimeIdentifiers = runtimeIdentifiers
|
||||
}.Build();
|
||||
.WithProjectDirectory(projectPath)
|
||||
.WithTargetFramework(framework)
|
||||
.WithRuntimeIdentifiers(runtimeIdentifiers)
|
||||
.Build();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -95,10 +94,9 @@ namespace Microsoft.Extensions.ProjectModel
|
|||
foreach(var framework in project.GetTargetFrameworks())
|
||||
{
|
||||
yield return new ProjectContextBuilder()
|
||||
{
|
||||
Project = project,
|
||||
TargetFramework = framework.FrameworkName
|
||||
}.Build();
|
||||
.WithProject(project)
|
||||
.WithTargetFramework(framework.FrameworkName)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,23 +12,77 @@ namespace Microsoft.Extensions.ProjectModel
|
|||
{
|
||||
public class ProjectContextBuilder
|
||||
{
|
||||
public Project Project { get; set; }
|
||||
private Project Project { get; set; }
|
||||
|
||||
public LockFile LockFile { get; set; }
|
||||
private LockFile LockFile { get; set; }
|
||||
|
||||
public GlobalSettings GlobalSettings { get; set; }
|
||||
private GlobalSettings GlobalSettings { get; set; }
|
||||
|
||||
public NuGetFramework TargetFramework { get; set; }
|
||||
private NuGetFramework TargetFramework { get; set; }
|
||||
|
||||
public IEnumerable<string> RuntimeIdentifiers { get; set; } = Enumerable.Empty<string>();
|
||||
private IEnumerable<string> RuntimeIdentifiers { get; set; } = Enumerable.Empty<string>();
|
||||
|
||||
public string RootDirectory { get; set; }
|
||||
private string RootDirectory { get; set; }
|
||||
|
||||
public string ProjectDirectory { get; set; }
|
||||
private string ProjectDirectory { get; set; }
|
||||
|
||||
public string PackagesDirectory { get; set; }
|
||||
private string PackagesDirectory { get; set; }
|
||||
|
||||
public string ReferenceAssembliesPath { get; set; }
|
||||
private string ReferenceAssembliesPath { get; set; }
|
||||
|
||||
public ProjectContextBuilder WithLockFile(LockFile lockFile)
|
||||
{
|
||||
LockFile = lockFile;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithProject(Project project)
|
||||
{
|
||||
Project = project;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithProjectDirectory(string projectDirectory)
|
||||
{
|
||||
ProjectDirectory = projectDirectory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithTargetFramework(NuGetFramework targetFramework)
|
||||
{
|
||||
TargetFramework = targetFramework;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithTargetFramework(string targetFramework)
|
||||
{
|
||||
TargetFramework = NuGetFramework.Parse(targetFramework);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithRuntimeIdentifiers(IEnumerable<string> runtimeIdentifiers)
|
||||
{
|
||||
RuntimeIdentifiers = runtimeIdentifiers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithReferenceAssembliesPath(string referenceAssembliesPath)
|
||||
{
|
||||
ReferenceAssembliesPath = referenceAssembliesPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithPackagesDirectory(string packagesDirectory)
|
||||
{
|
||||
PackagesDirectory = packagesDirectory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContextBuilder WithRootDirectory(string rootDirectory)
|
||||
{
|
||||
RootDirectory = rootDirectory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectContext Build()
|
||||
{
|
||||
|
@ -46,7 +100,7 @@ namespace Microsoft.Extensions.ProjectModel
|
|||
}
|
||||
|
||||
RootDirectory = GlobalSettings?.DirectoryPath ?? RootDirectory;
|
||||
PackagesDirectory = PackagesDirectory ?? PackageDependencyProvider.ResolveRepositoryPath(RootDirectory, GlobalSettings);
|
||||
PackagesDirectory = PackagesDirectory ?? PackageDependencyProvider.ResolvePackagesPath(RootDirectory, GlobalSettings);
|
||||
ReferenceAssembliesPath = ReferenceAssembliesPath ?? GetDefaultReferenceAssembliesPath();
|
||||
|
||||
LockFileLookup lockFileLookup = null;
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Microsoft.Extensions.ProjectModel.Resolution
|
|||
}
|
||||
}
|
||||
|
||||
public static string ResolveRepositoryPath(string rootDirectory, GlobalSettings settings)
|
||||
public static string ResolvePackagesPath(string rootDirectory, GlobalSettings settings)
|
||||
{
|
||||
// Order
|
||||
// 1. global.json { "packages": "..." }
|
||||
|
|
Loading…
Reference in a new issue