<!--
***********************************************************************************************
Microsoft.NET.Build.Extensions.ConflictResolution.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup Condition="'$(DisableHandlePackageFileConflicts)' != 'true'">
    <!-- Non-SDK using project.json or PackageReference, run after references are read from the lock/assets file -->
    <_HandlePackageFileConflictsAfter>ResolveNuGetPackageAssets</_HandlePackageFileConflictsAfter>

    <!-- In case ResolveNuGetPackageAssets is not run (eg: packages.config), ensure we run before targets that consume references -->
    <_HandlePackageFileConflictsBefore>ResolveAssemblyReferences</_HandlePackageFileConflictsBefore>
  </PropertyGroup>

  <Import Project="Microsoft.NET.DefaultPackageConflictOverrides.targets" />

  <UsingTask TaskName="ResolvePackageFileConflicts" AssemblyFile="$(MicrosoftNETBuildExtensionsTasksAssembly)" />
  <Target Name="_HandlePackageFileConflicts"
          BeforeTargets="$(_HandlePackageFileConflictsBefore)"
          AfterTargets="$(_HandlePackageFileConflictsAfter)"
          DependsOnTargets="GetFrameworkPaths;GetReferenceAssemblyPaths"
          Condition="'@(Reference)' != '' Or '@(ReferenceCopyLocalPaths)' != ''">
    <ResolvePackageFileConflicts References="@(Reference)"
                                 ReferenceCopyLocalPaths="@(ReferenceCopyLocalPaths)"
                                 PlatformManifests="@(PackageConflictPlatformManifests)"
                                 TargetFrameworkDirectories="$(TargetFrameworkDirectory)"
                                 PackageOverrides="@(PackageConflictOverrides)"
                                 PreferredPackages="$(PackageConflictPreferredPackages)">
      <Output TaskParameter="ReferencesWithoutConflicts" ItemName="_ReferencesWithoutConflicts" />
      <Output TaskParameter="ReferenceCopyLocalPathsWithoutConflicts" ItemName="_ReferenceCopyLocalPathsWithoutConflicts" />
      <Output TaskParameter="Conflicts" ItemName="_ConflictPackageFiles" />
    </ResolvePackageFileConflicts>

    <!-- Replace Reference / ReferenceCopyLocalPaths with the filtered lists.
         We must remove all and include rather than just remove since removal is based
         only on ItemSpec and duplicate ItemSpecs may exist with different metadata
         (eg: HintPath) -->
    <ItemGroup>
      <Reference Remove="@(Reference)" />
      <Reference Include="@(_ReferencesWithoutConflicts)" />
      <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
      <ReferenceCopyLocalPaths Include="@(_ReferenceCopyLocalPathsWithoutConflicts)" />
    </ItemGroup>
  </Target>
</Project>
