Skip to content

Commit 425349b

Browse files
committed
Switch ApiCompat to use PackageDownload
Turns out instead of using the apicompat project workaround we can use a PackageDownload reference to get the last shipped package. This allows us to do the apicompat check completely inside the project we are checking.
1 parent 1bf85a0 commit 425349b

File tree

11 files changed

+19
-79
lines changed

11 files changed

+19
-79
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,7 @@ dotnet build eng\service.proj /p:ServiceDirectory=eventhub /p:UpdateSourceOnBuil
229229
.NET is using the [ApiCompat tool](https://github.com/dotnet/arcade/tree/master/src/Microsoft.DotNet.ApiCompat) to enforce API compatibility between versions. Builds of GA'ed libraries will fail locally and in CI if there are breaking changes.
230230

231231
### How it works
232-
We use a dummy project called [ApiCompat](https://github.com/Azure/azure-sdk-for-net/tree/master/eng/ApiCompat/ApiCompat.csproj) to enforce API compatibility between the GA'ed libraries and the most recent version available on Nuget. This project includes package references to the GA'ed library and to Microsoft.DotNet.ApiCompat.
233-
Each library needs to provide a `ApiCompatVersion` property which is set to the last GA'ed version of the library which is used to compare APIs with the current to ensure no breaks
234-
have been introduced.
235-
The `ApiCompatVerification` target defined in `ApiCompat.csproj` is referenced in the [eng/Directory.Build.Data.targets](https://github.com/Azure/azure-sdk-for-net/blob/master/eng/Directory.Build.Data.targets) which causes this target to be executed for each csproj that has the `ApiCompatVersion` property set. For libraries that wish to disable the APICompat check they can remove the `ApiCompatVersion` property from their project. Our version bump automation will automatically add or increment the `ApiCompatVersion` property to the project when it detects that the version it is changing was a GA version which usually indicates that we just shipped that GA version and so it should be the new baseline for api checks.
232+
Each library needs to provide a `ApiCompatVersion` property which is set to the last GA'ed version of the library that will be used to compare APIs with the current to ensure no breaks have been introduced. Projects with this property set will download the specified package and the ApiCompat (Microsoft.DotNet.ApiCompat) tools package as part of the restore step of the project. Then as a post build step of the project it will run ApiCompat to verify the current APIs are compatible with the last GA'ed version of the APIs. For libraries that wish to disable the APICompat check they can remove the `ApiCompatVersion` property from their project. Our version bump automation will automatically add or increment the `ApiCompatVersion` property to the project when it detects that the version it is changing was a GA version which usually indicates that we just shipped that GA version and so it should be the new baseline for API checks.
236233

237234
### Releasing a new version of a GA'ed libary
238235
Since the [eng/Packages.Data.props](https://github.com/Azure/azure-sdk-for-net/blob/master/eng/Packages.Data.props) is currently maintained manually, you will need to update the version number for your library in this file when releasing a new version.

eng/ApiCompat/ApiCompat.csproj

Lines changed: 0 additions & 41 deletions
This file was deleted.

eng/ApiCompat/Directory.Build.targets

Lines changed: 0 additions & 6 deletions
This file was deleted.

eng/Directory.Build.Data.targets

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,22 @@
175175
Text="When UseProjectReferenceToAzureClients=true all Azure.* references should be Project References, but the following are not [@(ShouldBeProjectReference)]" />
176176
</Target>
177177

178-
<Target Name="RunApiCompat" AfterTargets="CoreBuild" Condition="'$(ApiCompatVersion)' != '' and '$(DesignTimeBuild)' != 'true' and '$(SkipApiCompat)' != 'true'">
179-
<MSBuild
180-
Projects="$(MSBuildThisFileDirectory)/ApiCompat/ApiCompat.csproj"
181-
Properties="TargetPackageName=$(PackageId);
182-
TargetPackageVersion=$(ApiCompatVersion);
183-
TargetOutputPath=$(IntermediateOutputPath);
184-
BaseIntermediateOutputPath=$(IntermediateOutputPath)\ApiCompat\"
185-
Targets="ApiCompatVerification"
186-
/>
178+
<ItemGroup Condition="'$(ApiCompatVersion)' != ''">
179+
<PackageDownload Include="$(PackageId)" Version="[$(ApiCompatVersion)]" />
180+
<PackageReference Include="Microsoft.DotNet.ApiCompat" />
181+
</ItemGroup>
182+
183+
<Target Name="_ResolveResolvedMatchingContract" BeforeTargets="ValidateApiCompatForSrc" Condition="'$(ApiCompatVersion)' != ''">
184+
<ItemGroup>
185+
<_ReferencePathDirectories Include="@(ReferencePath -> '%(RootDir)%(Directory)')" />
186+
<ResolvedMatchingContract Include="$(NuGetPackageRoot)\$(PackageId.ToLower())\$(ApiCompatVersion)\lib\$(TargetFramework)\$(TargetFileName)">
187+
<DependencyPaths>@(_ReferencePathDirectories->Distinct(), ',')</DependencyPaths>
188+
</ResolvedMatchingContract>
189+
</ItemGroup>
190+
</Target>
191+
192+
<Target Name="ApiCompatFinishedMessage" AfterTargets="ValidateApiCompatForSrc" Condition="'$(ApiCompatVersion)' != ''">
193+
<Message Text="Ran ApiCompat against %(ResolvedMatchingContract.Identity) using assemblies from $(IntermediateOutputPath)" Importance="High" />
187194
</Target>
188195

189196
<Import Project="$(CentralPackageVersionPackagePath)\Sdk.targets" />

eng/Packages.Data.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.6.1" />
6464
<PackageReference Update="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2" />
6565
<PackageReference Update="Microsoft.CodeAnalysis" Version="2.3.0" />
66+
<PackageReference Update="Microsoft.DotNet.ApiCompat" Version="5.0.0-beta.19552.1" />
6667
<PackageReference Update="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.5.1" />
6768
<PackageReference Update="Microsoft.Identity.Client" Version="4.16.1" />
6869
<PackageReference Update="Microsoft.Identity.Client.Extensions.Msal" Version="2.12.0" />

eng/scripts/Export-API.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ param (
77

88
$servicesProj = Resolve-Path "$PSScriptRoot/../service.proj"
99

10-
dotnet build /p:GenerateApiListingOnBuild=true /p:SkipApiCompat=true /p:GeneratePackageOnBuild=false /p:Configuration=Release /p:IncludeSamples=false /p:IncludeTests=false /p:Scope="$ServiceDirectory" /restore $servicesProj
10+
dotnet build /p:GenerateApiListingOnBuild=true /p:RunApiCompat=false /p:GeneratePackageOnBuild=false /p:Configuration=Release /p:IncludeSamples=false /p:IncludeTests=false /p:Scope="$ServiceDirectory" /restore $servicesProj

sdk/core/Azure.Core/Azure.Core.All.sln

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.Stora
161161
EndProject
162162
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigitalTwinsClientSample", "..\..\digitaltwins\Azure.DigitalTwins.Core\samples\DigitalTwinsClientSample\DigitalTwinsClientSample.csproj", "{635AF2FC-2E5D-4335-8F8D-72F25BD61C95}"
163163
EndProject
164-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiCompat", "..\..\..\eng\ApiCompat\ApiCompat.csproj", "{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}"
165-
EndProject
166164
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Analytics.Synapse.AccessControl", "..\..\synapse\Azure.Analytics.Synapse.AccessControl\src\Azure.Analytics.Synapse.AccessControl.csproj", "{3B583609-3429-4231-A690-BAB60A7CFF66}"
167165
EndProject
168166
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Analytics.Synapse.AccessControl.Tests", "..\..\synapse\Azure.Analytics.Synapse.AccessControl\tests\Azure.Analytics.Synapse.AccessControl.Tests.csproj", "{8833E803-A2DD-41F1-A264-7455A085AF47}"
@@ -1226,18 +1224,6 @@ Global
12261224
{635AF2FC-2E5D-4335-8F8D-72F25BD61C95}.Release|x64.Build.0 = Release|Any CPU
12271225
{635AF2FC-2E5D-4335-8F8D-72F25BD61C95}.Release|x86.ActiveCfg = Release|Any CPU
12281226
{635AF2FC-2E5D-4335-8F8D-72F25BD61C95}.Release|x86.Build.0 = Release|Any CPU
1229-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1230-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Debug|Any CPU.Build.0 = Debug|Any CPU
1231-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Debug|x64.ActiveCfg = Debug|Any CPU
1232-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Debug|x64.Build.0 = Debug|Any CPU
1233-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Debug|x86.ActiveCfg = Debug|Any CPU
1234-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Debug|x86.Build.0 = Debug|Any CPU
1235-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Release|Any CPU.ActiveCfg = Release|Any CPU
1236-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Release|Any CPU.Build.0 = Release|Any CPU
1237-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Release|x64.ActiveCfg = Release|Any CPU
1238-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Release|x64.Build.0 = Release|Any CPU
1239-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Release|x86.ActiveCfg = Release|Any CPU
1240-
{EC964E8B-58ED-42B3-BCAA-740FFEFFF155}.Release|x86.Build.0 = Release|Any CPU
12411227
{3B583609-3429-4231-A690-BAB60A7CFF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12421228
{3B583609-3429-4231-A690-BAB60A7CFF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
12431229
{3B583609-3429-4231-A690-BAB60A7CFF66}.Debug|x64.ActiveCfg = Debug|Any CPU

sdk/eventgrid/Azure.Messaging.EventGrid/src/Azure.Messaging.EventGrid.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<Version>4.0.0-beta.2</Version>
66
<PackageTags>Microsoft Azure EventGrid;Event Grid;Event Grid Publishing;</PackageTags>
77
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
8-
<EnableApiCompat>false</EnableApiCompat>
98
</PropertyGroup>
109

1110
<ItemGroup>

sdk/iot/Azure.Iot.Hub.Service/src/Azure.Iot.Hub.Service.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<PropertyGroup>
33
<AssemblyTitle>Azure IoT Hub Service Client SDK</AssemblyTitle>
44
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
5-
<EnableApiCompat>false</EnableApiCompat>
65
</PropertyGroup>
76

87
<!-- Nuget properties -->

sdk/storage/Azure.Storage.Blobs.ChangeFeed/src/Azure.Storage.Blobs.ChangeFeed.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
in addition to the breaking changes https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Blobs.ChangeFeed/BreakingChanges.txt
1414
</Description>
1515
<GenerateAPIListing>true</GenerateAPIListing>
16-
<EnableApiCompat>false</EnableApiCompat>
1716
</PropertyGroup>
1817
<ItemGroup>
1918
<PackageReference Include="System.Text.Json" />

0 commit comments

Comments
 (0)