public override bool Execute()
        {
            AnnotatedProjectReferencesWithSetTargetFramework = new ITaskItem[ProjectReferencesWithTargetFrameworks.Length];
            var targetFrameworkResolver = new TargetFrameworkResolver(RuntimeGraph);

            for (int i = 0; i < ProjectReferencesWithTargetFrameworks.Length; i++)
            {
                ITaskItem projectReference      = ProjectReferencesWithTargetFrameworks[i];
                string    targetFrameworksValue = projectReference.GetMetadata("RawTargetFrameworks");
                if (string.IsNullOrEmpty(targetFrameworksValue))
                {
                    targetFrameworksValue = projectReference.GetMetadata("TargetFrameworks");
                }
                string[] targetFrameworks = targetFrameworksValue.Split(';');

                string referringTargetFramework = projectReference.GetMetadata("ReferringTargetFramework");
                if (string.IsNullOrWhiteSpace(referringTargetFramework))
                {
                    referringTargetFramework = TargetFramework;
                }

                string bestTargetFramework = targetFrameworkResolver.GetBestSupportedTargetFramework(targetFrameworks, referringTargetFramework);
                if (bestTargetFramework == null)
                {
                    Log.LogError($"Not able to find a compatible supported target framework for {referringTargetFramework} in Project {Path.GetFileName(projectReference.ItemSpec)}. The Supported Configurations are {string.Join(", ", targetFrameworks)}");
                }

                projectReference.SetMetadata("SetTargetFramework", "TargetFramework=" + bestTargetFramework);
                AnnotatedProjectReferencesWithSetTargetFramework[i] = projectReference;
            }

            return(!Log.HasLoggedErrors);
        }
Ejemplo n.º 2
0
        public override bool Execute()
        {
            var bestTargetFrameworkList = new List <ITaskItem>();
            var targetframeworkResolver = new TargetFrameworkResolver(RuntimeGraph);

            foreach (ITaskItem buildTargetFramework in BuildTargetFrameworks)
            {
                string bestTargetFramework = targetframeworkResolver.GetBestSupportedTargetFramework(SupportedTargetFrameworks.Select(t => t.ItemSpec), buildTargetFramework.ItemSpec);
                if (bestTargetFramework != null)
                {
                    TaskItem item = new TaskItem(SupportedTargetFrameworks.First(t => t.ItemSpec == bestTargetFramework));
                    buildTargetFramework.CopyMetadataTo(item);
                    bestTargetFrameworkList.Add(item);
                }
            }

            BestTargetFrameworks = bestTargetFrameworkList.ToArray();
            return(!Log.HasLoggedErrors);
        }