A built-in tool for checking backward compatibility of NuGet packages #62541
-
It is hard to always care about backward compatibility when you develop NuGet packages, and easy to break it. For example, you may just add some optional parameter to a constructor or method.If you initially had a package
and then you decided to add some optional parameter to its constructor and forgot (or didn't want) to bump the major version, so that your package
You code will successfully compile and work if it directly uses
Because you broke backward compatibility you get an error:
I don't know a tool or a way to prevent runtime errors because of that. Especially, if you have more than a hundred NuGet dependencies that use each other transitively. So I wonder if there exists a tool to automatically check backward compatibility during compile time (via analysis of all Nuget dependencies), or during the publishing of a new package to NuGet (when you don't bump the major version)? I see there is a third-party project (tunnelvisionlabs/dotnet-compatibility) that does similar things, but I’m not sure about its quality, and I suppose that this functionality should be a part of .NET. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I've never used it myself, but my understanding is (You might find this script in the Roslyn repo to be helpful for updating If you prefer comparing built assemblies, check out |
Beta Was this translation helpful? Give feedback.
I've never used it myself, but my understanding is
Microsoft.CodeAnalysis.PublicApiAnalyzers
is a common solution for this.(You might find this script in the Roslyn repo to be helpful for updating
PublicAPI.Shipped.txt
.)If you prefer comparing built assemblies, check out
Microsoft.DotNet.AsmDiff
, which is what the runtime team uses to generate API diffs (SeeRunApiDiff.ps1
for their specific usage.)