Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to .NET Package Validation #33433

Open
1 of 4 tasks
heaths opened this issue Jan 12, 2023 · 4 comments
Open
1 of 4 tasks

Migrate to .NET Package Validation #33433

heaths opened this issue Jan 12, 2023 · 4 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. EngSys This issue is impacting the engineering system.
Milestone

Comments

@heaths
Copy link
Member

heaths commented Jan 12, 2023

We're using an old Microsoft.DotNet.ApiCompat package that doesn't evaluate compatible targets, and our own logic in eng/Directory.Build.Common.Targets below is currently causing issues like #33431:

  <Target Name="_ResolveResolvedMatchingContract" BeforeTargets="ValidateApiCompatForSrc" Condition="'$(ApiCompatVersion)' != ''">
    <ItemGroup>
      <_ReferencePathDirectories Include="@(ReferencePath -> '%(RootDir)%(Directory)')"  />
      <ResolvedMatchingContract Include="$(NuGetPackageRoot)\$(PackageId.ToLower())\$(ApiCompatVersion)\lib\$(TargetFramework)\$(TargetFileName)">
        <DependencyPaths>@(_ReferencePathDirectories->Distinct(), ',')</DependencyPaths>
      </ResolvedMatchingContract>
    </ItemGroup>
  </Target>

It was recommended to switch to built-in package validation now that we're moving to net7.0.

This will require some changes to any exceptions we have, so something we probably want to do only when working on changing all packages for #32597.

  • Remove old Microsoft.DotNet.ApiCompat package
  • Migrate any exceptions to the new format
  • Rename <ApiCompatVersion> and updating tooling, OR
  • Add <Target> to use <ApiCompatVersion> to define whatever property the built-in validation needs.
@heaths heaths added Client This issue points to a problem in the data-plane of the library. EngSys This issue is impacting the engineering system. labels Jan 12, 2023
@heaths heaths added this to the 2023-03 milestone Jan 12, 2023
@heaths heaths self-assigned this Jan 12, 2023
@heaths
Copy link
Member Author

heaths commented Jan 12, 2023

/cc @JoshLove-msft @hallipr @weshaggard

@heaths
Copy link
Member Author

heaths commented Feb 2, 2023

Be sure to take advantage of the cross-platform, cross-framework API checks as described.

@heaths
Copy link
Member Author

heaths commented Feb 22, 2023

There may be some problems:

  1. Can't find anything that would effectively ignore certain attributes being added or removed from a definition like we use now with Microsoft.DotNet.ApiCompat: <ApiCompatExcludeAttributeList>$(MSBuildThisFileDirectory)ApiListing.exclude-attributes.txt</ApiCompatExcludeAttributeList>
  2. Similarly, Microsoft.DotNet.GenAPI is also not published to nuget.org and a similar one had only one release and is deprecated. That generates the **/api/*.netstandard2.0.cs files we emit and compare in PRs.
  3. I imagine APIView relies partly on being informed about violations in a particular way, or even builds the RunApiCompat target, which is now all done during the Pack target e.g., dotnet pack.

To upgrade, we may need to rethink our whole stack.

/cc @JoshLove-msft @hallipr

@jsquire jsquire modified the milestones: 2023-03, Backlog Mar 27, 2023
@heaths
Copy link
Member Author

heaths commented May 4, 2023

I got some answers back from the .NET team that are relevant here:

To just run validation, you can install a global tool:

dotnet tool install --global Microsoft.DotNet.ApiCompat.Tool --version --prerelease

However, they state,

Note that I would not use the CLI frontend if you already operate in an msbuild environment. Reason for that:

  • Assembly references need to be passed in manually which msbuild targets already do for you.
  • Package baseline validation in msbuild handles downloading the baseline package (with a given baseline version) and passing it in.
  • You need an extra tool. APICompat’s msbuild frontend is part of the .NET SDK and can just be enabled via a property.
  • It’s currently undocumented and based on the download numbers not much used. Expect rough edges and bugs.

Additionally,

Using the msbuild flavor of ApiCompat only requires enabling a few settings inside an msbuild environment as documented (.NET Package Validation - .NET | Microsoft Learn):

<PropertyGroup>
  <EnablePackageValidation>true</EnablePackageValidation>
</PropertyGroup>

If you want to enable baseline package validation as well, set the following property. “x.x.x” refers to the version that you want to compare the just generated package against.

<PropertyGroup>
  <PackageValidationBaselineVersion>x.x.x</PackageValidationBaselineVersion>
</PropertyGroup>

Here are some additional settings for the msbuild frontend:

<PropertyGroup>
  <!—Enable attribute comparison optional rule. -->
  <ApiCompatEnableRuleAttributesMustMatch>true</ApiCompatEnableRuleAttributesMustMatch>
  <!—Enable cannot change parameter names optional rule. -->
  <ApiCompatEnableRuleCannotChangeParameterName>true</ApiCompatEnableRuleCannotChangeParameterName>
  <!—Perform validation in strict mode. This setting enforces public API in left (baseline) and right (current) to be strictly equal. This setting is usually only enabled during servicing in which public API shouldn’t change. -->
  <ApiCompatStrictMode>true</ApiCompatStrictMode>
</PropertyGroup>

<ItemGroup>
  <ApiCompatExcludeAttributesFile Include=”<path-to-doc-ids.txt>” />
</ItemGroup>

So we can still use our $(MSBuildThisFileDirectory)ApiListing.exclude-attributes.txt file.

@heaths heaths modified the milestones: Backlog, 2023-06 May 4, 2023
@jsquire jsquire modified the milestones: 2023-06, 2023-08 Jul 13, 2023
@jsquire jsquire modified the milestones: 2023-08, 2023-09 Aug 16, 2023
@jsquire jsquire modified the milestones: 2023-09, Backlog Sep 18, 2023
weshaggard added a commit that referenced this issue Apr 11, 2024
Just updated the dead link to point to the PR that remove the tool dotnet/arcade#14328.

At some point we will want to move to the new tool which is tracked at #33433
weshaggard added a commit that referenced this issue Apr 12, 2024
Just updated the dead link to point to the PR that remove the tool dotnet/arcade#14328.

At some point we will want to move to the new tool which is tracked at #33433
lmolkova pushed a commit to lmolkova/azure-sdk-for-net that referenced this issue Apr 12, 2024
Just updated the dead link to point to the PR that remove the tool dotnet/arcade#14328.

At some point we will want to move to the new tool which is tracked at Azure#33433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. EngSys This issue is impacting the engineering system.
Development

No branches or pull requests

2 participants