Skip to content

Commit fdded1c

Browse files
committed
Local and Copilot dev can generate public apis (#30500)
* Local and Copilot dev can generate public apis 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. 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. # Conflicts: # src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt # src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt
1 parent 3ee6e19 commit fdded1c

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

eng/NuGetVersions.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@
267267
Update="Microsoft.CodeAnalysis.PublicApiAnalyzers"
268268
Version="$(MicrosoftCodeAnalysisPublicApiAnalyzersVersion)"
269269
/>
270+
<PackageReference
271+
Update="Mono.ApiTools.MSBuildTasks"
272+
Version="$(MonoApiToolsMSBuildTasksPackageVersion)"
273+
/>
270274
<PackageReference
271275
Update="Tizen.UIExtensions.NUI"
272276
Version="$(TizenUIExtensionsVersion)"

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<SystemRuntimeCompilerServicesUnsafePackageVersion>6.1.2</SystemRuntimeCompilerServicesUnsafePackageVersion>
110110
<MicrosoftBuildFrameworkPackageVersion>17.9.5</MicrosoftBuildFrameworkPackageVersion>
111111
<MicrosoftBuildUtilitiesCorePackageVersion>17.9.5</MicrosoftBuildUtilitiesCorePackageVersion>
112+
<MonoApiToolsMSBuildTasksPackageVersion>0.4.0</MonoApiToolsMSBuildTasksPackageVersion>
112113
<!-- GLIDE - the android maven artifact in /src/Core/AndroidNative/maui/build.gradle -->
113114
<!-- must be kept in sync with the binding library version to it here: -->
114115
<_XamarinAndroidGlideVersion>4.16.0.13</_XamarinAndroidGlideVersion>

src/Controls/src/Core/Element/Element.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,7 @@ public bool EffectIsAttached(string name)
504504

505505
//this is only used by XAMLC, not added to public API
506506
[EditorBrowsable(EditorBrowsableState.Never)]
507-
#pragma warning disable RS0016 // Add public types and members to the declared API
508507
public INameScope transientNamescope;
509-
#pragma warning restore RS0016 // Add public types and members to the declared API
510508

511509
/// <summary>Returns the element that has the specified name.</summary>
512510
/// <param name="name">The name of the element to be found.</param>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,7 @@ void InitItemProperties(IView view, Flex.Item item)
464464
// Until we can rewrite the FlexLayout engine to handle measurement properly (without the "in measure mode" hacks)
465465
// we need to replace the default implementation of CrossPlatformMeasure.
466466
// And we need to disable the public API analyzer briefly, because it doesn't understand hiding.
467-
#pragma warning disable RS0016 // Add public types and members to the declared API
468467
new public Graphics.Size CrossPlatformMeasure(double widthConstraint, double heightConstraint)
469-
#pragma warning restore RS0016 // Add public types and members to the declared API
470468
{
471469
var layoutManager = _layoutManager ??= CreateLayoutManager();
472470

src/PublicAPI.targets

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
<Project>
22

3+
<PropertyGroup>
4+
<!-- The Copilot SWE always generates instead of trying to fix -->
5+
<PublicApiType Condition="'$(PublicApiType)' == '' and '$(GITHUB_WORKFLOW)' == 'Copilot'">Generate</PublicApiType>
6+
<!-- The normal CI workflows will NEVER generate, only validate -->
7+
<PublicApiType Condition="'$(PublicApiType)' == '' and ('$(CI)' == 'true' or '$(TF_BUILD)' == 'true')">Validate</PublicApiType>
8+
<!-- The Release builds will NEVER generate, only validate -->
9+
<PublicApiType Condition="'$(PublicApiType)' == '' and '$(Configuration)' != 'Debug'">Validate</PublicApiType>
10+
<!-- Local Debug workflows will generate -->
11+
<!--<PublicApiType Condition="'$(PublicApiType)' == '' and '$(Configuration)' == 'Debug'">Generate</PublicApiType>-->
12+
<!-- Fall back to validate -->
13+
<PublicApiType Condition="'$(PublicApiType)' == ''">Validate</PublicApiType>
14+
</PropertyGroup>
15+
316
<ItemGroup>
417
<PackageReference Remove="Microsoft.CodeAnalysis.PublicApiAnalyzers" />
5-
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" />
18+
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="All" Condition="'$(PublicApiType)' != 'Generate'" />
19+
<PackageReference Include="Mono.ApiTools.MSBuildTasks" PrivateAssets="all" Condition="'$(PublicApiType)' == 'Generate'" />
620
</ItemGroup>
721

822
<!-- for explicit TFMs -->
@@ -25,4 +39,19 @@
2539
<AdditionalFiles Include="@(PublicAPIFiles)" />
2640
</ItemGroup>
2741

28-
</Project>
42+
<Target Name="_GeneratePublicApiFiles"
43+
AfterTargets="Build"
44+
Condition="'$(TargetFramework)' != '' and '$(PublicApiType)' == 'Generate'"
45+
Inputs="$(TargetDir)$(AssemblyName).dll"
46+
Outputs="$(IntermediateOutputPath)GeneratePublicApiFiles.stamp">
47+
<GeneratePublicApiFiles
48+
Assembly="$(TargetDir)$(AssemblyName).dll"
49+
Files="@(PublicAPIFiles)"
50+
ReferenceSearchPaths="@(ReferencePath)" />
51+
<Touch Files="$(IntermediateOutputPath)GeneratePublicApiFiles.stamp" AlwaysCreate="True" />
52+
<ItemGroup>
53+
<FileWrites Include="$(IntermediateOutputPath)GeneratePublicApiFiles.stamp" />
54+
</ItemGroup>
55+
</Target>
56+
57+
</Project>

src/SingleProject/Resizetizer/src/Resizetizer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<!-- A small task to make sure everything depends on the same version of SkiaSharp -->
3737
<ItemGroup>
38-
<PackageReference Include="Mono.ApiTools.MSBuildTasks" Version="0.3.0" PrivateAssets="all" />
38+
<PackageReference Include="Mono.ApiTools.MSBuildTasks" PrivateAssets="all" />
3939
</ItemGroup>
4040
<PropertyGroup>
4141
<_AdjustmentsAssembly>$(PkgSvg_Skia)\lib\netstandard2.0\Svg.Skia.dll</_AdjustmentsAssembly>

0 commit comments

Comments
 (0)