Add MSBuild task to ApiCompat - #8523
Conversation
|
@ViktorHofer is this ready for review or did you want to first address the test failures? -- I didn't dig in yet to see if they're related. Let me know and I will have a look. |
6106ec2 to
c133b99
Compare
| @@ -0,0 +1,350 @@ | |||
| // Licensed to the .NET Foundation under one or more agreements. | |||
There was a problem hiding this comment.
Most of the file changes here are just a move of code over from ApiCompatRunner.cs. The only noticeable change is the addition of the isMsBuildTask parameter.
|
@ericstj I just resolved the test failures. I had to introduce an additional assembly to make sure that msbuild types aren't resolved when running in a console to avoid dependencies on MSBuild.* assemblies on .NETCoreApp which ship as part of msbuild. That said, there are still no breaking changes. |
|
Not sure when I'll have a chance to look over this in detail; adding a couple reviewers. I see this API compat version as somewhat of a dead-end as we'd like to eventually move to dotnet/sdk#18677 so that we don't have to be chasing language features in our tools. We should keep our investments here minimal while maintaining its current functionality. I'm OK with this change to add a task but try to keep the risk super low. |
c133b99 to
b704168
Compare
And apply code clean-up suggested by VS. Move core logic into Microsoft.DotNet.ApiCompat.Core
b704168 to
9fe5826
Compare
|
@ericstj the change itself is trivial and I already tested it on dotnet/runtime without any observable behavior changes (except for better perf). When looking at the changes you will see that most of it is just a move. Here's the summary of the change in more detail:
|
|
Me trying to motivate people to spend time reviewing this PR: Let's assume that 200 individuals rebuild dotnet/runtime once per day. With this change they should be able to build the libraries part of the repository roughly 40s faster which means that ~130 minutes of build time is saved per day and resources can be spent elsewhere. Another angle: CI builds will be able to build dotnet/runtime faster and a decent amount of money will be saved per day. If you are reading this and your review is requested, consider spending a few minutes of your time so that time is given back to the team, partners and community members by building dotnet/runtime more efficiently Thanks :) |
|
dotnet/runtime#66073 consumes these changes from my personal myget feed. You can see that no breaking changes are observable in dotnet/runtime :) |
| CustomErrorRegularExpression="^[a-zA-Z]+ :" | ||
| StandardOutputImportance="Low" | ||
| IgnoreExitCode="true"> | ||
| <ApiCompatTask Contracts="@(ResolvedMatchingContract)" |
There was a problem hiding this comment.
There might be value in keeping a target that runs out-of-proc as an exe. I'm mainly thinking about potential consumers using a very old MSBuild or folks that hit issues when trying to move the the in-proc version. We wouldn't want those consumers to have to do work to continue using the latest APICompat since this APICompat is legacy, so instead we would want them to move to the PackageValidation version which is the one we want to invest on moving forward.
There was a problem hiding this comment.
The purpose of this PR is to switch from out-of-process to in-process without any breaking changes for all consumers of the current version of ApiCompat. Community members like @filipnavara already expressed their interest in benefiting from the change.
If someone uses a very old MSBuild version, then the .targets file couldn't be loaded anyway because the Project element doesn't have any of the boilerplate attributes or the xml declaration element that were required by MSBuild years ago.
If someone wants to use this outside of the MSBuild world then nothing changes as the console application continues to be invokable directly from the package.
| } | ||
|
|
||
| _writer.WriteLine("Total Issues: {0}", _totalDifferences); | ||
| if (!_isMSBuildTask) |
There was a problem hiding this comment.
Why not output this on the task output as well?
There was a problem hiding this comment.
Left an inline comment. As we are using TextWriter in the code path, there isn't a good way to log with different verbosity levels. As the msbuild logger always logs errors, it can't be used in this case without creating an entire abstraction that would also touch other projects like AsmDiff and CciExtensions. Note that this code path is only avoided when the task doesn't output to a baseline file which means when invoked directly.
|
@joperezr thanks for the great feedback. Tests are now running for both the console and the msbuild version, comments are added where it makes sense and resolved a few behavior differences between the msbuild task and the console runner. Please find the changes in the recent commit. I also published a new version of ApiCompat to my private feed and will retrigger CI in the dotnet/runtime PR. |


Add an MSBuild task for ApiCompat to avoid out-of-process invocations and keep the existing console application to not break existing developer workflows.
The changes result in dotnet/runtime libs building 10-15% faster (on my machine, Surface Book 2) as hundreds of out-of-process invocations of ApiCompat are now happening in-proc.
This PR shouldn't introduce a breaking change:
_ApiCompatPath,_ApiCompatCommand(except for dotnet/runtime which I will update separately).The diff is a bit annoying to read...