<!--
***********************************************************************************************
Microsoft.NET.ApiCompat.Common.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>

  <!-- Expose the tasks for SDK consumption and for external use cases. -->
  <UsingTask TaskName="Microsoft.DotNet.ApiCompat.Task.ValidateAssembliesTask" AssemblyFile="$(DotNetApiCompatTaskAssembly)" />
  <UsingTask TaskName="Microsoft.DotNet.ApiCompat.Task.ValidatePackageTask" AssemblyFile="$(DotNetApiCompatTaskAssembly)" />

  <Target Name="CollectApiCompatInputs">
    <PropertyGroup Condition="'$(RoslynAssembliesPath)' == ''">
      <!-- If a custom roslyn assemblies path isn't provided, the opt-in switch 'ApiCompatUseRoslynToolsetPackagePath' is set to true and
           the roslyn toolset package is referenced, use the assemblies from that package. -->
      <_UseRoslynToolsetPackage Condition="'$(ApiCompatUseRoslynToolsetPackagePath)' == 'true' and '@(PackageReference->AnyHaveMetadataValue('Identity', 'Microsoft.Net.Compilers.Toolset'))' == 'true'">true</_UseRoslynToolsetPackage>

      <!-- CSharpCoreTargetsPath and VisualBasicCoreTargetsPath point to the same location, Microsoft.CodeAnalysis.CSharp and Microsoft.CodeAnalysis.VisualBasic
           are on the same directory as Microsoft.CodeAnalysis. So there is no need to distinguish between csproj or vbproj. -->
      <RoslynAssembliesPath Condition="'$(_UseRoslynToolsetPackage)' == 'true'">$([System.IO.Path]::GetDirectoryName('$(CSharpCoreTargetsPath)'))</RoslynAssembliesPath>
      
      <!-- Otherwise, default to the roslyn compiler provided by the SDK / Visual Studio. -->
      <RoslynAssembliesPath Condition="'$(_UseRoslynToolsetPackage)' != 'true'">$(RoslynTargetsPath)</RoslynAssembliesPath>

      <!-- The SDK stores the roslyn assemblies in the 'bincore' subdirectory. -->
      <RoslynAssembliesPath Condition="'$(MSBuildRuntimeType)' == 'Core'">$([System.IO.Path]::Combine('$(RoslynAssembliesPath)', 'bincore'))</RoslynAssembliesPath>
    </PropertyGroup>

    <!-- Respect legacy property and item names. -->
    <PropertyGroup>
      <ApiCompatGenerateSuppressionFile Condition="'$(ApiCompatGenerateSuppressionFile)' == ''">$(GenerateCompatibilitySuppressionFile)</ApiCompatGenerateSuppressionFile>
    </PropertyGroup>

    <ItemGroup>
      <ApiCompatSuppressionFile Include="$(CompatibilitySuppressionFilePath)"
                                Condition="'@(ApiCompatSuppressionFile)' == '' and '$(CompatibilitySuppressionFilePath)' != ''" />
    </ItemGroup>
    <!-- END: Respect legacy property and item names. -->

    <PropertyGroup>
      <_apiCompatDefaultProjectSuppressionFile>$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', 'CompatibilitySuppressions.xml'))</_apiCompatDefaultProjectSuppressionFile>
      <!-- Pass in a default suppression output file if non is supplied, and ApiCompatGenerateSuppressionFile is true. -->
      <ApiCompatSuppressionOutputFile Condition="'$(ApiCompatSuppressionOutputFile)' == '' and '$(ApiCompatGenerateSuppressionFile)' == 'true'">$(_apiCompatDefaultProjectSuppressionFile)</ApiCompatSuppressionOutputFile>
    </PropertyGroup>

    <!-- Pass in a default suppression file, if it exists. -->
    <ItemGroup Condition="'@(ApiCompatSuppressionFile)' == ''">
      <ApiCompatSuppressionFile Include="$(_apiCompatDefaultProjectSuppressionFile)"
                                Condition="Exists($(_apiCompatDefaultProjectSuppressionFile))" />
    </ItemGroup>
  </Target>

</Project>
