Skip to content

Local and Copilot dev can generate public apis #30500

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mattleibow
Copy link
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

Currently, the only way is to use the IDE and the lightbulb - or manually. This is often not successful and AI still struggles as well.

The new version of the Mono.ApiTools.MSBuildTasks package now has the ability to generate the files and they can be checked in during development to show the actual API changes.

Currently, local dev is not generating automatically because we need to see if this works for everyone. Copilot can help us test, and enabling is just a matter of uncommenting the one line.

The rules would be if this is release of CI, then it is set to Validate only, and then only if it is debug AND not CI (ie: local) will it enable generation.

Issues Fixed

The pain of trying to get IDEs to actually generate files in a multi-targeted world.

Currently, the only way is to use the IDE and the lightbulb - or manually.
This is often not successful and AI still struggles as well.

The new version of the Mono.ApiTools.MSBuildTasks package now has
the ability to generate the files and they can be checked in during
development to show the actual API changes.

Currently, local dev is not generating automatically because we need to
see if this works for everyone. Copilot can help us test, and enabling is
just a matter of uncommenting the one line.

The rules would be if this is release of CI, then it is set to Validate only,
and then only if it is debug AND not CI (ie: local) will it enable generation.
@Copilot Copilot AI review requested due to automatic review settings July 8, 2025 20:47
@mattleibow mattleibow requested a review from a team as a code owner July 8, 2025 20:47
@mattleibow mattleibow requested review from jfversluis and rmarinho July 8, 2025 20:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables automatic generation of public API files locally and via Copilot by integrating the updated Mono.ApiTools.MSBuildTasks package, adding conditional logic in the PublicAPI build targets, and recording new API changes.

  • Remove hard-coded version for Mono.ApiTools.MSBuildTasks and centralize versioning
  • Introduce PublicApiType conditions and a _GeneratePublicApiFiles target in PublicAPI.targets
  • Update PublicAPI.Unshipped.txt across TFMs for new API signatures and hide fields

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/SingleProject/Resizetizer/src/Resizetizer.csproj Drop explicit Version="0.3.0" to use central version management
src/PublicAPI.targets Add PublicApiType conditions, conditional analyzer/tasks package refs, and new generate target
src/Controls/src/Core/PublicAPI/*/PublicAPI.Unshipped.txt Record hiding of Element.transientNamescope and updated FlexLayout.CrossPlatformMeasure
src/Controls/src/Core/Layout/FlexLayout.cs Remove pragma warnings around the public CrossPlatformMeasure override
src/Controls/src/Core/Element/Element.cs Remove pragma warnings around the public transientNamescope field
eng/Versions.props Bump MonoApiToolsMSBuildTasksPackageVersion to 0.4.0
eng/NuGetVersions.targets Add Mono.ApiTools.MSBuildTasks central package reference
Comments suppressed due to low confidence (4)

src/PublicAPI.targets:40

  • Add automated tests (unit or integration) covering the new _GeneratePublicApiFiles target to verify that API files are generated correctly under the Generate condition.
  <Target Name="_GeneratePublicApiFiles" AfterTargets="Build" Condition="'$(TargetFramework)' != '' and '$(PublicApiType)' == 'Generate'">

src/Controls/src/Core/Layout/FlexLayout.cs:467

  • The RS0016 suppression pragmas around this public override were removed. This can lead to public API analyzer warnings. Reintroduce #pragma warning disable RS0016 before and #pragma warning restore RS0016 after the method to limit the suppression scope.
		new public Graphics.Size CrossPlatformMeasure(double widthConstraint, double heightConstraint)

src/Controls/src/Core/Element/Element.cs:507

  • The pragma disable/restore for RS0016 was removed around this field, causing potential analyzer failures. Add back #pragma warning disable RS0016 above and #pragma warning restore RS0016 below this declaration.
		public INameScope transientNamescope;

src/SingleProject/Resizetizer/src/Resizetizer.csproj:36

  • Removing the explicit version relies on central version management. Verify that eng/Versions.props defines the correct version to avoid mismatched package versions in local vs CI builds.
    <PackageReference Include="Mono.ApiTools.MSBuildTasks" PrivateAssets="all" />

Comment on lines +4 to +13
<!-- The Copilot SWE always generates instead of trying to fix -->
<PublicApiType Condition="'$(PublicApiType)' == '' and '$(GITHUB_WORKFLOW)' == 'Copilot'">Generate</PublicApiType>
<!-- The normal CI workflows or Release with NEVER generate, only validate -->
<PublicApiType Condition="'$(PublicApiType)' == '' and ('$(Configuration)' != 'Debug' or '$(CI)' == 'true' or '$(TF_BUILD)' == 'true')">Validate</PublicApiType>
<!-- WHEN WE ARE READY: Local Debug workflows will generate -->
<!-- <PublicApiType Condition="'$(PublicApiType)' == '' and '$(Configuration)' == 'Debug'">Generate</PublicApiType> -->
<!-- Fall back to validate -->
<PublicApiType Condition="'$(PublicApiType)' == ''">Validate</PublicApiType>
</PropertyGroup>

Copy link
Preview

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The conditional logic for PublicApiType is fairly complex. Consider adding descriptive comments for each condition or refactoring into smaller, named targets for better readability and future maintenance.

Suggested change
<!-- The Copilot SWE always generates instead of trying to fix -->
<PublicApiType Condition="'$(PublicApiType)' == '' and '$(GITHUB_WORKFLOW)' == 'Copilot'">Generate</PublicApiType>
<!-- The normal CI workflows or Release with NEVER generate, only validate -->
<PublicApiType Condition="'$(PublicApiType)' == '' and ('$(Configuration)' != 'Debug' or '$(CI)' == 'true' or '$(TF_BUILD)' == 'true')">Validate</PublicApiType>
<!-- WHEN WE ARE READY: Local Debug workflows will generate -->
<!-- <PublicApiType Condition="'$(PublicApiType)' == '' and '$(Configuration)' == 'Debug'">Generate</PublicApiType> -->
<!-- Fall back to validate -->
<PublicApiType Condition="'$(PublicApiType)' == ''">Validate</PublicApiType>
</PropertyGroup>
<!-- Set PublicApiType for Copilot workflows -->
<PublicApiType Condition="'$(PublicApiType)' == '' and '$(GITHUB_WORKFLOW)' == 'Copilot'">Generate</PublicApiType>
</PropertyGroup>
<Target Name="_SetPublicApiTypeForCopilot" Condition="'$(PublicApiType)' == '' and '$(GITHUB_WORKFLOW)' == 'Copilot'">
<PropertyGroup>
<PublicApiType>Generate</PublicApiType>
</PropertyGroup>
</Target>
<Target Name="_SetPublicApiTypeForCI" Condition="'$(PublicApiType)' == '' and ('$(Configuration)' != 'Debug' or '$(CI)' == 'true' or '$(TF_BUILD)' == 'true')">
<PropertyGroup>
<PublicApiType>Validate</PublicApiType>
</PropertyGroup>
</Target>
<Target Name="_SetDefaultPublicApiType" Condition="'$(PublicApiType)' == ''">
<PropertyGroup>
<PublicApiType>Validate</PublicApiType>
</PropertyGroup>
</Target>

Copilot uses AI. Check for mistakes.

Comment on lines +40 to +45
<Target Name="_GeneratePublicApiFiles" AfterTargets="Build" Condition="'$(TargetFramework)' != '' and '$(PublicApiType)' == 'Generate'">
<GeneratePublicApiFiles
Assembly="$(TargetDir)$(AssemblyName).dll"
Files="@(AdditionalFiles)"
ReferenceSearchPaths="@(ReferencePath)" />
</Target>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add Inputs/Outputs, so it doesn't run on every incremental build for every project?

Is this right?

Inputs="$(TargetDir)$(AssemblyName).dll"
Outputs="@(PublicAPIFiles)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants