protected override void ExecuteCore()
        {
            var log          = new MSBuildLog(Log);
            var packageRanks = new PackageRank(PreferredPackages);

            // resolve conflicts at compile time
            var referenceItems = GetConflictTaskItems(References, ConflictItemType.Reference).ToArray();

            var compileConflictScope = new ConflictResolver <ConflictItem>(packageRanks, log);

            compileConflictScope.ResolveConflicts(referenceItems,
                                                  ci => ItemUtilities.GetReferenceFileName(ci.OriginalItem),
                                                  HandleCompileConflict);

            // resolve conflicts that class in output
            var runtimeConflictScope = new ConflictResolver <ConflictItem>(packageRanks, log);

            runtimeConflictScope.ResolveConflicts(referenceItems,
                                                  ci => ItemUtilities.GetReferenceTargetPath(ci.OriginalItem),
                                                  HandleRuntimeConflict);

            var copyLocalItems = GetConflictTaskItems(ReferenceCopyLocalPaths, ConflictItemType.CopyLocal).ToArray();

            runtimeConflictScope.ResolveConflicts(copyLocalItems,
                                                  ci => ItemUtilities.GetTargetPath(ci.OriginalItem),
                                                  HandleRuntimeConflict);

            var otherRuntimeItems = GetConflictTaskItems(OtherRuntimeItems, ConflictItemType.Runtime).ToArray();

            runtimeConflictScope.ResolveConflicts(otherRuntimeItems,
                                                  ci => ItemUtilities.GetTargetPath(ci.OriginalItem),
                                                  HandleRuntimeConflict);


            // resolve conflicts with platform (eg: shared framework) items
            // we only commit the platform items since its not a conflict if other items share the same filename.
            var platformConflictScope = new ConflictResolver <ConflictItem>(packageRanks, log);
            var platformItems         = PlatformManifests?.SelectMany(pm => PlatformManifestReader.LoadConflictItems(pm.ItemSpec, log)) ?? Enumerable.Empty <ConflictItem>();

            platformConflictScope.ResolveConflicts(platformItems, pi => pi.FileName, pi => { });
            platformConflictScope.ResolveConflicts(referenceItems.Where(ri => !referenceConflicts.Contains(ri.OriginalItem)),
                                                   ri => ItemUtilities.GetReferenceTargetFileName(ri.OriginalItem),
                                                   HandleRuntimeConflict,
                                                   commitWinner: false);
            platformConflictScope.ResolveConflicts(copyLocalItems.Where(ci => !copyLocalConflicts.Contains(ci.OriginalItem)),
                                                   ri => ri.FileName,
                                                   HandleRuntimeConflict,
                                                   commitWinner: false);
            platformConflictScope.ResolveConflicts(otherRuntimeItems,
                                                   ri => ri.FileName,
                                                   HandleRuntimeConflict,
                                                   commitWinner: false);

            ReferencesWithoutConflicts = RemoveConflicts(References, referenceConflicts);
            ReferenceCopyLocalPathsWithoutConflicts = RemoveConflicts(ReferenceCopyLocalPaths, copyLocalConflicts);
            Conflicts = CreateConflictTaskItems(allConflicts);
        }
Example #2
0
        protected override void ExecuteCore()
        {
            var log              = new MSBuildLog(Log);
            var packageRanks     = new PackageRank(PreferredPackages);
            var packageOverrides = new PackageOverrideResolver <ConflictItem>(PackageOverrides);

            //  Treat assemblies from FrameworkList.xml as platform assemblies that also get considered at compile time
            IEnumerable <ConflictItem> compilePlatformItems = null;

            if (TargetFrameworkDirectories != null && TargetFrameworkDirectories.Any())
            {
                var frameworkListReader = new FrameworkListReader(BuildEngine4);

                compilePlatformItems = TargetFrameworkDirectories.SelectMany(tfd =>
                {
                    return(frameworkListReader.GetConflictItems(Path.Combine(tfd.ItemSpec, "RedistList", "FrameworkList.xml"), log));
                });
            }

            // resolve conflicts at compile time
            var referenceItems = GetConflictTaskItems(References, ConflictItemType.Reference).ToArray();

            var compileConflictScope = new ConflictResolver <ConflictItem>(packageRanks, packageOverrides, log);

            compileConflictScope.ResolveConflicts(referenceItems,
                                                  ci => ItemUtilities.GetReferenceFileName(ci.OriginalItem),
                                                  HandleCompileConflict);

            if (compilePlatformItems != null)
            {
                compileConflictScope.ResolveConflicts(compilePlatformItems,
                                                      ci => ci.FileName,
                                                      HandleCompileConflict);
            }

            // resolve conflicts that class in output
            var runtimeConflictScope = new ConflictResolver <ConflictItem>(packageRanks, packageOverrides, log);

            runtimeConflictScope.ResolveConflicts(referenceItems,
                                                  ci => ItemUtilities.GetReferenceTargetPath(ci.OriginalItem),
                                                  HandleRuntimeConflict);

            var copyLocalItems = GetConflictTaskItems(ReferenceCopyLocalPaths, ConflictItemType.CopyLocal).ToArray();

            runtimeConflictScope.ResolveConflicts(copyLocalItems,
                                                  ci => ItemUtilities.GetTargetPath(ci.OriginalItem),
                                                  HandleRuntimeConflict);

            var otherRuntimeItems = GetConflictTaskItems(OtherRuntimeItems, ConflictItemType.Runtime).ToArray();

            runtimeConflictScope.ResolveConflicts(otherRuntimeItems,
                                                  ci => ItemUtilities.GetTargetPath(ci.OriginalItem),
                                                  HandleRuntimeConflict);


            // resolve conflicts with platform (eg: shared framework) items
            // we only commit the platform items since its not a conflict if other items share the same filename.
            var platformConflictScope = new ConflictResolver <ConflictItem>(packageRanks, packageOverrides, log);
            var platformItems         = PlatformManifests?.SelectMany(pm => PlatformManifestReader.LoadConflictItems(pm.ItemSpec, log)) ?? Enumerable.Empty <ConflictItem>();

            if (compilePlatformItems != null)
            {
                platformItems = platformItems.Concat(compilePlatformItems);
            }

            platformConflictScope.ResolveConflicts(platformItems, pi => pi.FileName, pi => { });
            platformConflictScope.ResolveConflicts(referenceItems.Where(ri => !referenceConflicts.Contains(ri.OriginalItem)),
                                                   ri => ItemUtilities.GetReferenceTargetFileName(ri.OriginalItem),
                                                   HandleRuntimeConflict,
                                                   commitWinner: false);
            platformConflictScope.ResolveConflicts(copyLocalItems.Where(ci => !copyLocalConflicts.Contains(ci.OriginalItem)),
                                                   ri => ri.FileName,
                                                   HandleRuntimeConflict,
                                                   commitWinner: false);
            platformConflictScope.ResolveConflicts(otherRuntimeItems,
                                                   ri => ri.FileName,
                                                   HandleRuntimeConflict,
                                                   commitWinner: false);

            ReferencesWithoutConflicts = RemoveConflicts(References, referenceConflicts);
            ReferenceCopyLocalPathsWithoutConflicts = RemoveConflicts(ReferenceCopyLocalPaths, copyLocalConflicts);
            Conflicts = CreateConflictTaskItems(allConflicts);
        }