Skip to content
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

Adding basic nuget package download API #16443

Merged
merged 5 commits into from
Mar 23, 2021
Merged

Conversation

sfoslund
Copy link
Member

No description provided.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@sfoslund
Copy link
Member Author

@wli3 is this along the lines of what you were thinking? Do you know if there's a API for extracting a nupkg once it's on disk?

var findPackageByIdResource = await source.GetResourceAsync<FindPackageByIdResource>();
var nupkgPath = Path.Combine(_packageInstallDir, packageId, packageVersion.ToNormalizedString(), $"{packageId}.{packageVersion.ToNormalizedString()}.nupkg");
Directory.CreateDirectory(Path.GetDirectoryName(nupkgPath));
using (FileStream destinationStream = File.Create(nupkgPath))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using (FileStream destinationStream = File.Create(nupkgPath))
using var destinationStream = File.Create(nupkgPath);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an analyzer for this issue? It is not too useful to correct it one place without further enforce

@pranavkm
Copy link
Contributor

Do you know if there's a API for extracting a nupkg once it's on disk?

https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Packaging/PackageExtractor.cs#L20 perhaps

@wli3
Copy link

wli3 commented Mar 20, 2021

@zivkan could we use this API in production?

@wli3
Copy link

wli3 commented Mar 20, 2021

Also create an issue and link to the Epic, so that we know there are a lot of things are not done. At least add multiple feeds support (nuget.config), authentication, signing verification, proper error handling and cancelation token

@sfoslund sfoslund marked this pull request as ready for review March 22, 2021 17:29
@sfoslund sfoslund requested a review from zivkan March 22, 2021 17:55
@sfoslund
Copy link
Member Author

@wli3 I added a method to extract the package as well, if you want to take a look.

@zivkan
Copy link
Member

zivkan commented Mar 22, 2021

@zivkan could we use this API in production?

VS setup is using it, so you wouldn't be the first. NuGet doesn't have a list of "supported public APIs" separate from "unsupported public APIs".

Anyway, it is the only API we have to extract a nupkg, so we should be thoughtful that every single customer who wants to use our SDK to extract packages will be using this API. Therefore, I hope that if someone makes changes to the API that they create a backwards compatible overload, rather than breaking the API.

Unfortunately this is best reassurance I can offer, but since NuGet started using the public API analyzers, other people in my team are starting to question changes to any public API, so wouldn't expect that we break it.

The dotnet SDK has the advantage that NuGet inserts into it. Therefore, as long as your code fails to compile, or tests fail, we'll catch breaking APIs in NuGet early, and then can revert the changes. I can't imagine why we'd make a breaking change to PackageExtractor and be unable to provide a compatible overload.

@sfoslund sfoslund mentioned this pull request Mar 23, 2021
15 tasks
@sfoslund sfoslund merged commit 7af705d into dotnet:main Mar 23, 2021
@sfoslund sfoslund deleted the NuGetApi branch March 23, 2021 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants