msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Feature reques - build-wide pre- and post- step

Open JanKrivanek opened this issue 2 months ago • 2 comments

Context

Requested by @nohwnd in context of terminal logger work:

The feature ask we were discussing in the morning:

Add post solution (and pre solution) step

In VSTest we would like the ability to easily add work after all projects in solution finished build. We run tests as part of build, and those tests produce file artifacts. Example of a file artifact is a project1.coverage and project2.coverage. We would like to merge those files into a sigle solution.coverage file through a custom "task".

Similarly each test project has a result, which can be thought of as a non-file artifact. e.g. total 3 tests, 1 test passed, 2 tests failed. Which we would like to summarize into solution wide summary. This is currently hard coded into terminal logger.

Ideally the merging would work independently of terminal logger.

Similar request was recently voiced as well by Identity build team

Discussed options

  • Add ability to add pre- and post- build targets on solution metaproj (though - this might not work in VS, this would not work for builds initiated not through the solution, transfering information via ItemGroups would need to be investigated - as this will need info from other projects).

  • Add ability for a logger to log into a logging service (as that has access to build wide info and it already hase build started and finished events). Possible downside - possibility of deadlocks or other ordering-specific situations arised from logger sending log messages

JanKrivanek avatar Apr 29 '24 08:04 JanKrivanek

  • Add ability to add pre- and post- build targets on solution metaproj (though - this might not work in VS, this would not work for builds initiated not through the solution, transfering information via ItemGroups would need to be investigated - as this will need info from other projects).

This is possible with solution imports. It does have all the caveats you describe.

rainersigwald avatar Apr 29 '24 14:04 rainersigwald

See for example the solution-level NuGet restore stuff:

  1. Gets imported to solution metaprojects through https://github.com/dotnet/NuGet.BuildTasks/blob/4caf040c5a74b633c2260d7a8744737a93942a84/src/Microsoft.NuGet.Build.Tasks/ImportBeforeAfter/Microsoft.NuGet.Solution.ImportAfter.targets
  2. Does special solution-y things via checks on this condition https://github.com/NuGet/NuGet.Client/blob/4020570fd78096035b551a5ac0869ca995f4dbed/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets#L55

rainersigwald avatar Apr 30 '24 15:04 rainersigwald

@JanKrivanek does it resolve the issue?

AR-May avatar May 07 '24 14:05 AR-May