dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.66k stars 1.06k forks source link

[Package Validation] Add an opt-in feature to automatically calculate the package to download for API comparison #25268

Open ericstj opened 2 years ago

ericstj commented 2 years ago

We initially had a feature which would automatically calculate and download the latest stable package for a library.

That was removed in https://github.com/dotnet/sdk/pull/17880 because it has a rather high cost of putting network access in front of NuGet's restore step and can result in non-determinism in the build -- since the source is external it always needs to be checked for a new version.

We've heard from others that this is a missing feature, and some have gone to lengths to implement this themselves by generating projects and having those projects reference their stable library using FloatingVersion notation then exposing the resolved library to the task.

NuGet support for floating version notation in a PackageDownload would help, but that's currently not supported https://github.com/NuGet/Home/issues/7709.

We should consider an opt-in feature that enables automatic calculation of the last stable package.

ericstj commented 2 years ago

I had another rather crazy idea for this. As an alternative to calculating the version and adding a PackageDownload could we participate in the restore process and provide items to the RestoreTask via the RestoreGraphEntry https://github.com/NuGet/NuGet.Client/blob/f52a83999070237288d7e1c8ec5934a65eda77ac/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs#L27 where we express the need for a floating package reference and tie that to an assets file and not any actual project? Could that let us leverage NuGet to do the download without causing side effects to the project or incurring the cost overhead of generating a project?

ViktorHofer commented 2 years ago

See also the comments in https://github.com/dotnet/sdk/issues/23772 which I just closed as a dup.