Skip to content

Commit

Permalink
Add support for NuGet lock files version 2 (google#694)
Browse files Browse the repository at this point in the history
If [NuGet central package
management](https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management)
is enabled, V2 lock files will be generated when restoring projects.
Check out [NuGet
source](https://github.com/NuGet/NuGet.Client/blob/a59e64507383b64bcfbe9bf63b34aca946ab0da9/src/NuGet.Core/NuGet.Commands/PackagesLockFileBuilder.cs#L119-L128)
for reference.

Since version V2 is backward compatible with V1, the required change to
support it is straightforward.
  • Loading branch information
giovanni-bozzano authored Dec 8, 2023
1 parent 3bd465b commit dd26cdc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/lockfile/parse-nuget-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (e NuGetLockExtractor) Extract(f DepFile) ([]PackageDetails, error) {
return []PackageDetails{}, fmt.Errorf("could not extract from %s: %w", f.Path(), err)
}

if parsedLockfile.Version != 1 {
return []PackageDetails{}, fmt.Errorf("could not extract: unsupported lock file version")
if parsedLockfile.Version != 1 && parsedLockfile.Version != 2 {
return []PackageDetails{}, fmt.Errorf("could not extract: unsupported lock file version %d", parsedLockfile.Version)
}

return parseNuGetLock(*parsedLockfile)
Expand Down
2 changes: 1 addition & 1 deletion pkg/lockfile/parse-nuget-lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ func TestParseNuGetLock_InvalidVersion(t *testing.T) {

packages, err := lockfile.ParseNuGetLock("fixtures/nuget/empty.v0.json")

expectErrContaining(t, err, "unsupported lock file version")
expectErrContaining(t, err, "unsupported lock file version 0")
expectPackages(t, packages, []lockfile.PackageDetails{})
}

0 comments on commit dd26cdc

Please sign in to comment.