-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Switch to PublicApiAnalyzers #7018
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
Conversation
This is the modern replacement for GenAPI that Roslyn itself has been using for a while, and it makes clearer errors and works cross-platform.
This is also public, shipping API.
with <Target Name="CreatePublicAPI" BeforeTargets="BeforeBuild"> <MakeDir Directories="@(AdditionalFiles->'%(RootDir)%(Directory)')" /> <Touch Files="@(AdditionalFiles)" AlwaysCreate="true" /> </Target>
Get-ChildItem -Recurse PublicAPI.Shipped.txt | % {Remove-Item $_} Get-ChildItem -Recurse PublicAPI.Unshipped.txt | % {Rename-Item $_ PublicAPI.Shipped.txt -Force ; New-Item $_ -ItemType file}
The vast majority of our API is not nullable aware so disable this.
The generic parameter was correct but this avoids this C# error: error CS1658: Type parameter declaration must be an identifier not a type. See also error CS0081.
The new PublicAPI.Shipped.txt stuff should do the trick.
@ladipro, I'd especially like your review on this because of the StringTools API-tracking stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenAPI has served us well but I'm excited to see us adopt more evolved solution!
The merge I just pushed will demonstrate what the errors look like in CI (that's totally why I'm doing it, nothing to do with laziness). |
Not too bad IMO: https://dev.azure.com/dnceng/public/_build/results?buildId=1456841&view=results Now I'll push a better merge. |
7fb4b92
to
3faffd6
Compare
3faffd6
to
2f47dc4
Compare
Let my failure to do this be a WARNING and a CAVEAT to this: I used "fix all in project" and it only did the first TF of that project. You can instead use "fix all in solution" to get everything (per dotnet/roslyn-analyzers#4954 (comment)). |
<GenAPIAssemblyName>$(AssemblyName)</GenAPIAssemblyName> | ||
<GenAPIAssemblyName Condition="'$(GenAPIAssemblyName)' == ''">$(MSBuildProjectName)</GenAPIAssemblyName> | ||
<GenAPIShortFrameworkIdentifier Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">net</GenAPIShortFrameworkIdentifier> | ||
<GenAPIShortFrameworkIdentifier Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETStandard'">netstandard</GenAPIShortFrameworkIdentifier> | ||
<GenAPIShortFrameworkIdentifier Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">netstandard</GenAPIShortFrameworkIdentifier> | ||
<GenAPITargetPath>$(RepoRoot)ref\$(GenAPIAssemblyName)\$(GenAPIShortFrameworkIdentifier)\$(GenAPIAssemblyName).cs</GenAPITargetPath> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed GenAPITargetPath wasn't used before. Was it getting picked up somewhere else in the build, or was this an unused property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was used in the GenAPI package's targets somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, and we're not using them anymore so should we get rid of some of these variables? Or proactively rename them to match the analyzer we're moving to.
Consider this a nit though.
This is used only in Debug and the difference is only the one thing so I don't think it's worth having separate Debug/Release APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you! What is supposed to go into the Unshipped
files? The documentation just says they must exist; no details given.
Lol, yeah, we should write up some docs. The PublicApiAnalyzers process goes like this:
The idea is to distinguish between new public API surface in a given release (can still be changed if we figure out a better API shape, because we don't have to maintain compat with daily builds) and shipped public API surface (which we shouldn't change because someone might be using it). I'll write up a doc. |
Primarily to give a place to mention what we now need to do for PublicApiAnalyzers.
This allows us to delete the `ref` folder entirely. This was an intermediate state of D.B.targets: ``` <PropertyGroup Condition="'$(GenerateReferenceAssemblySource)' == 'true'"> <GenAPIAssemblyName>$(AssemblyName)</GenAPIAssemblyName> <GenAPIAssemblyName Condition="'$(GenAPIAssemblyName)' == ''">$(MSBuildProjectName)</GenAPIAssemblyName> <GenAPIShortFrameworkIdentifier Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">net</GenAPIShortFrameworkIdentifier> <GenAPIShortFrameworkIdentifier Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETStandard'">netstandard</GenAPIShortFrameworkIdentifier> <GenAPIShortFrameworkIdentifier Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">netstandard</GenAPIShortFrameworkIdentifier> <PublicApiTfm Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">net</PublicApiTfm> <PublicApiTfm Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework' and $([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) == '3.5'">net35</PublicApiTfm> <PublicApiTfm Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETStandard'">netstandard</PublicApiTfm> <PublicApiTfm Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">netstandard</PublicApiTfm> <GenAPIFolderPath>$(RepoRoot)ref\$(GenAPIAssemblyName)\$(GenAPIShortFrameworkIdentifier)\</GenAPIFolderPath> </PropertyGroup> <ItemGroup Condition="'$(GenerateReferenceAssemblySource)' == 'true'"> <!-- Ensure API stability for shipping packages --> <PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" PrivateAssets="all" /> <AdditionalFiles Include="PublicAPI/$(PublicApiTfm)/PublicAPI.Shipped.txt" /> <AdditionalFiles Include="PublicAPI/$(PublicApiTfm)/PublicAPI.Unshipped.txt" /> </ItemGroup> <Target Name="MovePublicAPI" BeforeTargets="BeforeBuild" Condition="'$(GenerateReferenceAssemblySource)' == 'true'"> <MakeDir Directories="$(MSBuildProjectDirectory)/PublicAPI/$(PublicApiTfm)" /> <Copy SourceFiles="$(GenAPIFolderPath)PublicAPI.Shipped.txt;$(GenAPIFolderPath)PublicAPI.Unshipped.txt" DestinationFolder="$(MSBuildProjectDirectory)/PublicAPI/$(PublicApiTfm)" /> </Target> ```
Conflicts: ref/Microsoft.Build/net/Microsoft.Build.cs ref/Microsoft.Build/netstandard/Microsoft.Build.cs
Abandon GenAPI for the new hotness in public API change tracking, which
Based off the
vs17.0
branch so I didn't accidentally canonize new API.