Skip to content

Make APICompat friendlier #2297

@ericstj

Description

@ericstj

Today I had to do the following to demonstrate API Compat usage.

  <PropertyGroup>
    <RunApiCompat>true</RunApiCompat>
    <RunApiCompatForSrc>true</RunApiCompatForSrc>
    <RunMatchingRefApiCompat>false</RunMatchingRefApiCompat>
  </PropertyGroup>
  
  <ItemGroup>
    <ResolvedMatchingContract Include="..\old\apiCompat.dll" />
    <PackageReference Include="Microsoft.DotNet.ApiCompat" Version="1.0.0-beta.19170.2" PrivateAssets="All" />
  </ItemGroup>

  <Target Name="defineContractOutputPath" BeforeTargets="RunMatchingRefApiCompat">
    <ItemGroup>
      <_ContractDependencyDirectoriesTemp Include="@(ReferencePath -> '%(RootDir)%(Directory)')" />
      <_ContractDependencyDirectories Condition="'%(_ContractDependencyDirectoriesTemp.ReferenceSourceTarget)' == 'ProjectReference'" Include="%(_ContractDependencyDirectories.Identity)" />
      <_ContractDependencyDirectories Condition="'%(_ContractDependencyDirectoriesTemp.ReferenceSourceTarget)' != 'ProjectReference'" Include="%(_ContractDependencyDirectories.Identity)" />
    </ItemGroup>
  </Target>

Some notes.

  • By default we should run normal API compat, and not reverse API compat. Properties should only be required to turn it off, or to enable reverse compat.
  • ResolvedMatchingContract is a terrible name. We should rename it. I've convinced myself I'm OK with this name: contract is good enough and is more appropriate than "reference assembly" since we use API compat for past versions as well.
  • We should also have some options for how to define it. Once NuGet download-only packages are available this might be an interesting use-case. In the meantime we should have an example for how to create a project to do this.
  • When ContractOutputPath isn't defined we should reuse ReferencePath directories as contract dependencies. This should be suppressible with a property. I don't think this is a good idea as it could lead to missed issues in cases where dependencies are also things that might be under test. Instead I've made it easier to pass contract dependencies.

Metadata

Metadata

Assignees

Labels

area-Infrastructure-librariesArea maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etc

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions