Skip to content

Support NuGet lockfiles#6031

Closed
anthony-c-martin wants to merge 9 commits intodependabot:mainfrom
anthony-c-martin:lockfiles
Closed

Support NuGet lockfiles#6031
anthony-c-martin wants to merge 9 commits intodependabot:mainfrom
anthony-c-martin:lockfiles

Conversation

@anthony-c-martin
Copy link
Copy Markdown

First draft at addressing #1303

I'm super unfamiliar with this project as well as Ruby, so guidance is very welcome.

@ldeluigi
Copy link
Copy Markdown

Any news on this?

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

Hei @ldeluigi, you just got an update yesterday at #1303. Let's try to not be too pushy please, we get a lot of notifications around here 😅.

@ldeluigi
Copy link
Copy Markdown

Hei @ldeluigi, you just got an update yesterday at #1303. Let's try to not be too pushy please, we get a lot of notifications around here 😅.

whops: I'm sorry!

@abdulapopoola abdulapopoola added the L: dotnet:nuget NuGet packages via nuget or dotnet label Mar 30, 2023
Copy link
Copy Markdown
Member

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

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

👋 Sorry for the delay, I've been wanting to get to this and finally had a little time this evening.

A few thoughts:

  1. First, a big caveat, I've never worked with Dotnet/Nuget myself, so any comments may simply be due to misunderstanding.
  2. This looks really solid from a general "dependabot" structure perspective, nice job! 🎉
  3. We split out the dockerfiles by ecosystem, so you'll need to rebase to install dotnet into https://github.com/dependabot/dependabot-core/blob/d0bd472495eda2eabb71040a59dbbfeb4dfb4931/nuget/Dockerfile
  4. I really like that you're leveraging the native tooling... we want to migrate this direction as much as we can.
  5. Today we do all our dotnet updating via ruby/regex text parsing hackery... now that we'd have the native tooling available, does it also support updating the manifest itself? Such that we could start to leverage that to migrate away from our existing text hackery? Obviously something we'd handle in a different PR, but just want to know if we should be creating a new ticket to track opportunities for migration.
  6. CI looks unhappy, mind fixing?

If you can rebase and fix that last CI failure, then I'm 👍 on merging.

I'll also ask a teammate who's more familiar with Nuget to take a look just in case I'm overlooking something, but this looks pretty straightforward so I don't expect any issues. Even if we don't cover all use cases, even adding support for some of them would be a great start for others to build out further.

Thanks again! And sorry took so long to review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm curious: why does this fixture not have a file extension? No other fixture in this folder is extension-less.

I was also surprised that it's plural "lockfiles" when the content appears to be only a single lockfile?

@jeffwidman
Copy link
Copy Markdown
Member

Nudge @anthony-c-martin any chance of addressing my questions?☝️

Be great to move this forward!

@jeffwidman
Copy link
Copy Markdown
Member

Note to self: Since this adds lockfile support, we'll need to ensure it supports the lockfile-only strategy, see how other ecosystems are wired up here:

@anthony-c-martin
Copy link
Copy Markdown
Author

@jeffwidman - sorry, I've been pretty busy! Will try and take a look over the comments this weekend and sync the branch with main.

@Porges
Copy link
Copy Markdown

Porges commented Apr 21, 2023

I'm not entirely sure you want --force-evaluate since that could affect packages other than the one that :dependabot: is trying to update? At least for me it is sufficient to run the basic dotnet restore command to update the lockfile after :dependabot: has updated the .csproj files with the new version.

@anthony-c-martin
Copy link
Copy Markdown
Author

  1. I really like that you're leveraging the native tooling... we want to migrate this direction as much as we can.
  2. Today we do all our dotnet updating via ruby/regex text parsing hackery... now that we'd have the native tooling available, does it also support updating the manifest itself? Such that we could start to leverage that to migrate away from our existing text hackery? Obviously something we'd handle in a different PR, but just want to know if we should be creating a new ticket to track opportunities for migration.

These are great points, and something I was wondering about. The dotnet add <package> will take care of both updating the .csproj file, and then updating lockfiles afterwards. There's also dotnet outdated, but it's not built-in tooling, so you may want to understand the implications of taking a dependency.

A caveat that I can think of that needs investigating - You've already got some pretty sophisticated tooling here (for example, you're looking inside Directory.Build.props files for updates). I'm not sure whether the native tools actually support equivalent functionality for some of these edge cases.

@ryanbrandenburg
Copy link
Copy Markdown
Contributor

I'm not sure whether the native tools actually support equivalent functionality for some of these edge cases.

I can confirm that dotnet add package <PackageName> --version <version> does not work in the Directory.Build.props scenario (it replaced Version="$(PackageVersion)" with Version="1.2.3").

@neotrow
Copy link
Copy Markdown

neotrow commented Jun 28, 2023

is there any news on this? Would love to see depandabot to support nuget lock files :-)

@anthony-c-martin anthony-c-martin changed the title [POC] NuGet lockfile implementation Support NuGet lockfiles Jul 7, 2023
@anthony-c-martin
Copy link
Copy Markdown
Author

@jeffwidman sorry for the delay, I've merged and fixed up the CI.

Comment on lines +195 to +196
project_file = files.find { |f| project_file?(f) && File.dirname(f.name) == File.dirname(lock_file.name) }
next if project_file.nil?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you explain this check?

It seems like there can be more than one lockfile (packages.lock.json) per project?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In general there's a lockfile for every project in a solution, and transitive dependencies are represented in each lockfile.

So for example, you could have a structure like the following:

  • dirs.sln (solution file, contains refs to projA & projB)
  • projA/projA.csproj (proj file, has nuget reference to nugetX)
  • projB/projB.csproj (proj file, has project reference to projA)

If dependabot runs for the solution file (dirs.sln), and decides to bump nugetX, you would expect to see:

  • projA/packages.lock.json has a direct dependency, and is updated
  • projB/packages.lock.json has a transitive dependency, and is also updated

Here's a concrete example of what this looks like in my project:

@anthony-c-martin
Copy link
Copy Markdown
Author

@jeffwidman, @Nishnha - out of interest, is there any way to manually test this against a repo prior to merging?

@Nishnha
Copy link
Copy Markdown
Member

Nishnha commented Jul 25, 2023

@jeffwidman, @Nishnha - out of interest, is there any way to manually test this against a repo prior to merging?

You could set up a smoke test https://github.com/dependabot/smoke-tests

@anthony-c-martin anthony-c-martin force-pushed the lockfiles branch 13 times, most recently from e04ad05 to 8fb77ae Compare September 22, 2023 05:34
@anthony-c-martin anthony-c-martin force-pushed the lockfiles branch 2 times, most recently from 24a84da to 697aa77 Compare September 23, 2023 13:45
@anthony-c-martin
Copy link
Copy Markdown
Author

anthony-c-martin commented Sep 23, 2023

@jeffwidman, @Nishnha - out of interest, is there any way to manually test this against a repo prior to merging?

You could set up a smoke test https://github.com/dependabot/smoke-tests

Thanks! I've done this, and temporarily updated this branch to point to my fork, to demonstrate that it's working: https://github.com/dependabot/dependabot-core/actions/runs/6284091213/job/17065146529?pr=6031

@milkshakeuk
Copy link
Copy Markdown

@jeffwidman @anthony-c-martin @Nishnha are there any updates on this?

@na1307
Copy link
Copy Markdown
Contributor

na1307 commented May 5, 2024

Since the last commit, nuget's dependabot logic has been rewritten in C#. I think this PR should (probably) be updated.

@JamieMagee
Copy link
Copy Markdown
Member

Closing this for now, as NuGet support has largely been rewritten in C# and this PR has diverged a lot.

Thank you @anthony-c-martin for the implementation, and thank you @na1307 for picking it up.

@JamieMagee JamieMagee closed this May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: dotnet:nuget NuGet packages via nuget or dotnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.