public ProjectContextBuilder Clone() { var builder = new ProjectContextBuilder() .WithLockFile(LockFile) .WithProject(Project) .WithProjectDirectory(ProjectDirectory) .WithTargetFramework(TargetFramework) .WithRuntimeIdentifiers(RuntimeIdentifiers) .WithReferenceAssembliesPath(ReferenceAssembliesPath) .WithPackagesDirectory(PackagesDirectory) .WithRootDirectory(RootDirectory) .WithProjectResolver(ProjectResolver) .WithLockFileResolver(LockFileResolver) .WithProjectReaderSettings(ProjectReaderSettings); if (IsDesignTime) { builder.AsDesignTime(); } return(builder); }
/// <summary> /// Produce all targets found in the lock file associated with this builder. /// Returns an empty enumerable if there is no lock file /// (making this unsuitable for scenarios where the lock file may not be present, /// such as at design-time) /// </summary> /// <returns></returns> public IEnumerable <ProjectContext> BuildAllTargets() { ProjectDirectory = Project?.ProjectDirectory ?? ProjectDirectory; EnsureProjectLoaded(); LockFile = LockFile ?? LockFileResolver(ProjectDirectory); if (LockFile != null) { var deduper = new HashSet <string>(); foreach (var target in LockFile.Targets) { var context = Clone() .WithTargetFramework(target.TargetFramework) .WithRuntimeIdentifiers(new[] { target.RuntimeIdentifier }).Build(); var id = $"{context.TargetFramework}/{context.RuntimeIdentifier}"; if (deduper.Add(id)) { yield return(context); } } } else { // Build a context for each framework. It won't be fully valid, since it won't have resolved data or runtime data, but the diagnostics will show that. foreach (var framework in Project.GetTargetFrameworks()) { var builder = new ProjectContextBuilder() .WithProject(Project) .WithTargetFramework(framework.FrameworkName); if (IsDesignTime) { builder.AsDesignTime(); } yield return(builder.Build()); } } }