Skip to content

NuGet pack "The DateTimeOffset specified cannot be converted into a Zip file timestamp" #7001

Closed
NuGet/NuGet.Client
#3793

Description

@oskogstad

Details about Problem

Running nuget pack .nuspec fails with the message
"The DateTimeOffset specified cannot be converted into a Zip file timestamp."

It happens with nuget 4.6.2 for a .dll file that has LastWriteTime 31/12/1979 23:00:00 +00:00

image

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):
NuGet.exe
version (4.6.2.5055)

OS version (i.e. win10 v1607 (14393.321)):
Windows 10 v 1803 Build 17134.81

Worked before? If so, with which NuGet version:
Works with v. 4.5.1.4879

Detailed repro steps so we can see the same problem

Run nuget pack NuGetDateTimeOffsetIssue.nuspec in the attached sample project
on nuget.exe v. 4.6 or higher.

Or:
Make a class library that includes NuGet log4net.Ext.Json v. 1.2.15.14586
Run nuget spec <lib-name>
Run nuget pack <.nuspec>

Verbose Logs

~/Downloads ❯❯❯ ./nuget\(1\).exe pack -verbosity detailed C:/dev/.../authenticationhost.nuspec                                                                                          
NuGet Version: 4.6.2.5055
Attempting to build package from 'authenticationhost.nuspec'.
The DateTimeOffset specified cannot be converted into a Zip file timestamp.
Parameter name: value
System.ArgumentOutOfRangeException: The DateTimeOffset specified cannot be converted into a Zip file timestamp.
Parameter name: value
   at System.IO.Compression.ZipArchiveEntry.set_LastWriteTime(DateTimeOffset value)
   at NuGet.Packaging.PackageBuilder.CreatePart(ZipArchive package, String path, Stream sourceStream, DateTimeOffset lastWriteTime)
   at NuGet.Packaging.PackageBuilder.WriteFiles(ZipArchive package, HashSet`1 filesWithoutExtensions)
   at NuGet.Packaging.PackageBuilder.Save(Stream stream)
   at NuGet.Commands.PackCommandRunner.BuildPackage(PackageBuilder builder, String outputPath)
   at NuGet.Commands.PackCommandRunner.BuildFromNuspec(String path)
   at NuGet.Commands.PackCommandRunner.BuildPackage()
   at NuGet.CommandLine.PackCommand.ExecuteCommand()
   at NuGet.CommandLine.Command.ExecuteCommandAsync()
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)

Sample Project

NuGetDateTimeOffsetIssue.zip

image

After fix (PR is in review)

Input file for test:
image

Now this file modified in 1959 after packing looks like this:
image

Activity

  1. dtivel commented on Dec 7, 2018

    @dtivel
    Contributor

    The ZipArchiveEntry.LastWriteTime setter enforces a min and max value. This behavior is documented.

    A NuGet solution could be:

    • If a value is less than the min value, we could set LastWriteTime to the min value.
    • Similarly, if a value is greater than the max value, we could set LastWriteTime to the max value.

    There is precedence for this approach.

  2. bobbwhy commented on Jan 9, 2019

    @bobbwhy

    I ran across this issue on a Mac OS 10.14 running dotnet 2.2 and nuget 4.8.
    My windows and linux machines do NOT have this issue.

    can anyone tell me how to do a work around please?
    OR at least where is the ZipArchiveEntry.LastWriteTime located?
    Is it project wide? system wide?

    thank you.

  3. Zukka commented on Mar 21, 2019

    @Zukka

    There is a fix for this problem?

  4. mfkl commented on Mar 21, 2019

    @mfkl

    Also running into this. Modified date looks like ‎30 ‎November ‎1979, ‏‎00:00:00

  5. Zukka commented on Mar 22, 2019

    @Zukka

    Thanks to my colleague Federico for the workaround:
    1- Check if there is one or more files with date like 01/01/xxxx 00:00
    image

    2 - with Total Commander or other tools change the date value, for example in my fix I changed to 01/01/2018.
    With Total Commander, select the file, then select menu File-Change Attribute...

    image

  6. mfkl commented on Mar 22, 2019

    @mfkl

    That's a workaround for the bug, not a bugfix :) Both 7z and nuget need a fix.

  7. Zukka commented on Mar 22, 2019

    @Zukka

    That's a workaround for the bug, not a bugfix :) Both 7z and nuget need a fix.

    Updated the comment. From fix to workaround ;)

  8. per-samuelsson commented on Jun 17, 2019

    @per-samuelsson

    Also hit by this. Running simple dotnet pack on a project file with <PackAsATool> being set, and on .NET Core 3.0 Preview.

    Here's the environment:

    .NET Core SDK (reflecting any global.json):
     Version:   3.0.100-preview5-011568
     Commit:    b487ff10aa
    
    Runtime Environment:
     OS Name:     Windows
     OS Version:  10.0.17134
     OS Platform: Windows
     RID:         win10-x64
     Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\
    
    Host (useful for support):
      Version: 3.0.0-preview5-27626-15
      Commit:  61f30f5a23
    
    .NET Core SDKs installed:
      1.0.0-rc4-004771 [C:\Program Files\dotnet\sdk]
      1.0.0 [C:\Program Files\dotnet\sdk]
      1.0.3 [C:\Program Files\dotnet\sdk]
      1.1.0 [C:\Program Files\dotnet\sdk]
      2.0.0 [C:\Program Files\dotnet\sdk]
      2.1.202 [C:\Program Files\dotnet\sdk]
      2.1.400 [C:\Program Files\dotnet\sdk]
      2.1.502 [C:\Program Files\dotnet\sdk]
      2.1.505 [C:\Program Files\dotnet\sdk]
      2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
      2.1.602 [C:\Program Files\dotnet\sdk]
      2.2.101 [C:\Program Files\dotnet\sdk]
      2.2.103 [C:\Program Files\dotnet\sdk]
      3.0.100-preview5-011568 [C:\Program Files\dotnet\sdk]
    
    .NET Core runtimes installed:
      Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 1.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 1.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.WindowsDesktop.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    
  9. 51 remaining items

  10. tobias-klein commented on Sep 22, 2020

    @tobias-klein

    I would appreciate a fix of this issue. It's currently breaking the Windows build of Ezra Project.

  11. mbre777 commented on Oct 14, 2020

    @mbre777

    Still happening - please fix this as it's breaking my CI.

  12. erdembayar commented on Nov 13, 2020

    @erdembayar
    Contributor

    I'm interested in this one as my first 'nuget pack' challenge during "Customer sprint".

  13. self-assigned this
    on Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Category:Quality WeekFunctionality:PackPriority:1Product:NuGet.exeProduct:dotnet.exeType:Bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions