protected override IEnumerable<ProjectContext> BuildProjectContexts(Project project)
 {
     foreach (var framework in project.GetTargetFrameworks())
     {
         yield return CreateBaseProjectBuilder(project)
             .AsDesignTime()
             .WithTargetFramework(framework.FrameworkName)
             .Build();
     }
 }
示例#2
0
 protected override IEnumerable <ProjectContext> BuildProjectContexts(Project project)
 {
     foreach (var framework in project.GetTargetFrameworks())
     {
         yield return(CreateBaseProjectBuilder(project)
                      .AsDesignTime()
                      .WithTargetFramework(framework.FrameworkName)
                      .Build());
     }
 }
示例#3
0
        /// <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());
                }
            }
        }