<!--
***********************************************************************************************
coverlet.collector.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.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="CopyCoverletDataCollectorFiles" AfterTargets="ComputeFilesToPublish">
    <ItemGroup>
      <CoverletDataCollectorFiles Include="$(MSBuildThisFileDirectory)\*.*" />
    </ItemGroup>
    <Copy SourceFiles="@(CoverletDataCollectorFiles)" DestinationFolder="$(PublishDir)%(RecursiveDir)" />

  </Target>
  <Target Name="SetXPlatDataCollectorPath" BeforeTargets="VSTest">
    <PropertyGroup>
      <VSTestTestAdapterPath>$(VSTestTestAdapterPath);$(MSBuildThisFileDirectory)</VSTestTestAdapterPath>
    </PropertyGroup>
  </Target>

  <PropertyGroup>
    <_CoverletSdkNETCoreSdkVersion>$(NETCoreSdkVersion)</_CoverletSdkNETCoreSdkVersion>
    <_CoverletSdkNETCoreSdkVersion Condition="$(_CoverletSdkNETCoreSdkVersion.Contains('-'))">$(_CoverletSdkNETCoreSdkVersion.Split('-')[0])</_CoverletSdkNETCoreSdkVersion>
    <_CoverletSdkMinVersionWithDependencyTarget>3.1.300</_CoverletSdkMinVersionWithDependencyTarget>
    <_CoverletSourceRootTargetName>CoverletGetPathMap</_CoverletSourceRootTargetName>
    <_CoverletSourceRootTargetName Condition="'$([System.Version]::Parse($(_CoverletSdkNETCoreSdkVersion)).CompareTo($([System.Version]::Parse($(_CoverletSdkMinVersionWithDependencyTarget)))))' &gt;= '0' ">InitializeSourceRootMappedPaths</_CoverletSourceRootTargetName>
  </PropertyGroup>

  <Target Name="ReferencedPathMaps" BeforeTargets="CoreCompile" DependsOnTargets="ResolveProjectReferences" >
    <MSBuild Projects="@(AnnotatedProjects->'%(FullPath)')"
             Targets="$(_CoverletSourceRootTargetName)"
             Properties="TargetFramework=%(AnnotatedProjects.NearestTargetFramework)"
             SkipNonexistentTargets="true">
      <Output TaskParameter="TargetOutputs"
              ItemName="_LocalTopLevelSourceRoot" />
    </MSBuild>
    <ItemGroup>
      <_byProject Include="@(_LocalTopLevelSourceRoot->'%(MSBuildSourceProjectFile)')" OriginalPath="%(Identity)" />
      <_mapping Include="@(_byProject->'%(Identity)|%(OriginalPath)=%(MappedPath)')" />
    </ItemGroup>
    <PropertyGroup>
      <_sourceRootMappingFilePath>$([MSBuild]::EnsureTrailingSlash('$(OutputPath)'))CoverletSourceRootsMapping</_sourceRootMappingFilePath>
    </PropertyGroup>
    <WriteLinesToFile File="$(_sourceRootMappingFilePath)" Lines="@(_mapping)"
                      Overwrite="true" Encoding="Unicode"
                      Condition="'@(_mapping)'!=''"
                      WriteOnlyWhenDifferent="true" />
    <ItemGroup>
      <FileWrites Include="$(_sourceRootMappingFilePath)" Condition="'@(_mapping)'!=''" />
    </ItemGroup>
  </Target>
</Project>
