dependabot-core icon indicating copy to clipboard operation
dependabot-core copied to clipboard

Support for NuGet package lock files

Open xt0rted opened this issue 5 years ago • 22 comments

In NuGet 4.9 I think it is they added support for package lock files using the setting RestorePackagesWithLockFile which is part of your .csproj or .props file chain. This creates a file called packages.lock.json alongside your project file. The spec for this can be found at https://github.com/NuGet/Home/wiki/Enable-repeatable-package-restore-using-lock-file

xt0rted avatar Aug 09 '19 00:08 xt0rted

Super keen to do this, but it's going to require some work - at the moment Dependabot does all of its .NET updating in Ruby, and we'll need to change that. We might want to continue this over at https://github.com/dependabot/dependabot-core/issues/541?

greysteil avatar Aug 09 '19 08:08 greysteil

@jerriep. given your great work with dotnet-outdated, do you have any advice on how Dependabot can also update any associated dependency lock files in its PR?

Is the best way to run dotnet restore, perhaps with --force-evaluate, or are there other better ways?

gitfool avatar Feb 19 '20 20:02 gitfool

@gitfool No, I was not even aware of this new feature until you just pointed it out. You may have to resort to using some of the NuGet Client libraries to achieve this.

Maybe look at this PR and the linked specifications to see whether there are some hints to guide you.

jerriep avatar Feb 20 '20 00:02 jerriep

is there any news regarding this topic?

vmcbaptista avatar Apr 14 '21 22:04 vmcbaptista

Would also be interested in support for this feature. Any updates?

edumserrano avatar Jun 21 '21 00:06 edumserrano

Would also be interested in support for this.

majastrz avatar Jul 13 '21 23:07 majastrz

I've written up a workaround for this at https://david.gardiner.net.au/2021/05/dependabot-nuget-lockfiles.html, but would much prefer it was handled natively given that dependabot stops maintaining the PR once a 'foreign' commit has been added.

flcdrg avatar Sep 27 '21 00:09 flcdrg

Much needed feature!

ldeluigi avatar Oct 07 '21 09:10 ldeluigi

As a workaround, I define a GitHub action in my repository that kicks dotnet restore. Note: You need to use Personal Access Token to re-trigger another GitHub Actions (like unit testing)

  restore:
    name: Update NuGet Lock Files
    if: contains(github.head_ref, 'dependabot') && github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
        with:
          ref: ${{ github.head_ref }}
          token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      - uses: actions/[email protected]
        with:
          dotnet-version: 6.0.x

      - run: dotnet restore --force-evaluate
      - id: diff
        continue-on-error: true
        run: |
          git add -N .
          git diff --name-only --exit-code
      - if: steps.diff.outcome == 'failure'
        run: |
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git config user.name "github-actions[bot]"
          git add .
          git commit -m "chore(deps): update NuGet lock file"
          git push

nogic1008 avatar Feb 16 '22 23:02 nogic1008

@greysteil - do you have any technical pointers to share on what a solution would look like? I'd be happy to contribute a fix if there's a clear path forward.

anthony-c-martin avatar Nov 02 '22 19:11 anthony-c-martin

You could look at what Renovate does since it already handles package lock files: https://github.com/renovatebot/renovate/blob/b6670159c4c6c3e6e1b07829604b2c3301f54162/lib/modules/manager/nuget/artifacts.ts#L98 (Or just switch to Renovate.)

gitfool avatar Nov 02 '22 20:11 gitfool

@greysteil - do you have any technical pointers to share on what a solution would look like? I'd be happy to contribute a fix if there's a clear path forward.

I'm not the right person to ask anymore (I'm a PM working across all of GitHub's security products these days, and no longer an expert on Dependabot). @jeffwidman @deivid-rodriguez do either of you have pointers here?

greysteil avatar Nov 02 '22 21:11 greysteil

Thanks! I've hacked my way through an implementation (PR #6031). @jeffwidman / @deivid-rodriguez - would appreciate some guidance if you've got the time!

anthony-c-martin avatar Nov 03 '22 13:11 anthony-c-martin

👍🏻 for having this. We've recently added packages.lock file to .NET nanoFramework libraries and tools and now each update from dependabot fails to build because the packages.lock file is not updated along.

Here's the most recent PR failing on the pipeline build: nanoframework/nanoFirmwareFlasher#174

josesimoes avatar Nov 30 '22 09:11 josesimoes

Thanks! I've hacked my way through an implementation (PR #6031). @jeffwidman / @deivid-rodriguez - would appreciate some guidance if you've got the time!

Any updates @jeffwidman @deivid-rodriguez ?

milkshakeuk avatar Jan 18 '23 20:01 milkshakeuk

Hei, nice! We love lockfiles around here :)

Both @jeffwidman and I are going through the backlog of PRs, so we should eventually get to this. I personally know nothing about nuget so I will need to read on a few things to properly review that PR. On top of that, I first want to get merged a bunch of other PR I haven't yet got to merging. But I'll get to this one soonish unless Jeff beats me to it!

deivid-rodriguez avatar Jan 18 '23 21:01 deivid-rodriguez

Hei, nice! We love lockfiles around here :)

Both @jeffwidman and I are going through the backlog of PRs, so we should eventually get to this. I personally know nothing about nuget so I will need to read on a few things to properly review that PR. On top of that, I first want to get merged a bunch of other PR I haven't yet got to merging. But I'll get to this one soonish unless Jeff beats me to it!

I'm glad to read this!

ldeluigi avatar Jan 20 '23 09:01 ldeluigi

The lack of support for Nuget lockfiles also extends to the dependency graph functionality and vulnerability analysis. Transitive dependencies are not detected even when they have critical vulnerabilities listed against them...

Porges avatar Apr 04 '23 21:04 Porges

👋 Sorry for the delay.

I reviewed https://github.com/dependabot/dependabot-core/pull/6031, which would add support for NuGet package lock files to :dependabot: and the PR itself looked very straightforward / solid, but I had a couple of questions about general NuGet things. Since I haven't yet gotten a reply from the PR author, can anyone here pop by that PR and provide answers?

Be great to move this forward!

jeffwidman avatar Apr 19 '23 22:04 jeffwidman

Hello, what is the status of this issue?

sowa705 avatar Jan 16 '24 15:01 sowa705

#6031 is too old. I tried to fix it, but I don't know where or how to fix it.

na1307 avatar May 05 '24 07:05 na1307

It should be relatively easy. You need to enable lock file generation in the https://github.com/dependabot/dependabot-core/tree/main/nuget/helpers/lib/NuGetUpdater which can actually cause issues with group updates.

Or since there is DotNet executable you can run DotNet restore after update before commit is finalized.

trejjam avatar May 05 '24 08:05 trejjam