4

When I want to pack my library as a NuGet package, I get the below error

The DateTimeOffset specified cannot be converted into a Zip file timestamp

I'm using the below command to pack my project:

dotnet msbuild /t:pack /p:Configuration=Release /p:SourceLinkCreate=true
Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55

3 Answers3

3

The problem is; some DLL files have invalid dates for a zip file (like 31/12/1979). You can overcome this issue by updating all the invalid DLL files modification date. Here's the Powershell script that updates all the invalid DLLs.

gci -path "C:\" -rec -file *.dll | Where-Object {$_.LastWriteTime -lt (Get-Date).AddYears(-20)} | %  { try { $_.LastWriteTime = '01/01/2020 00:00:00' } catch {} }

It sets all the invalid DLL dates to 01/01/2000. Change the path parameter for your computer. My GitHub repositories are on my C drive so I'm running this -path C:\.

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
  • this doesn't harm anything on your computer. it filters only the DLLs with the modification date is set 20 years ago. so you can run this PowerShell script multiple times without any issues. – Alper Ebicoglu Apr 06 '20 at 09:34
  • Just out of curiosity: how did you end up with dll with last write time from 1979? – Peska Apr 07 '20 at 18:20
  • 1
    Some Microsoft DLLs are timestamped with 31/12/1979. I don't know the reason why it's so. Some CI/CD pipelines of Microsoft I guess. See https://github.com/NuGet/Home/issues/7001 – Alper Ebicoglu Apr 09 '20 at 14:07
3

Seems that in most of cases (basing on research in github issues) the problem was related to Microsoft.Extensions.* packages. In my case update to newer version of Microsoft.Extensions.* (from 3.1.0 to 3.1.4) fixed the problem. For reference :

https://github.com/dotnet/extensions/issues/2750

and mentioned in comments :

https://github.com/NuGet/Home/issues/7001

HNB
  • 297
  • 3
  • 7
2

I made a console app to fix invalid dates in a drive (cross-platform). It sets the LastModificationDate to 01/01/2000. You can just run it without any arguments. It will run in all your drives. Also you can specify a directory to search in.

Source-code on GitHub:

Usage:

FileBulkDateChanger.exe

or

FileBulkDateChanger.exe C:\

For MAC/Linux,

dotnet FileBulkDateChanger.dll

Run this tool and forget about this issue :)

Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55