Search code examples
azure-devopsnuget

Why does Azure Devops change the date on dlls downloaded from Nuget?


I notice that files such as EntityFramework.Dll are deployed with the current time. I have been experiencing this error and I resolved it by copying dlls from my development machine to the overwrite deployed dlls.

What causes the date to change on the dlls?

azure-pipelines.yml is

trigger:
- master

pool:
  vmImage: 'VS2017-Win2016'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  inputs:
    restoreSolution: '**\*.sln'
    feedsToUse: config

    nugetConfigPath: 'MyService.ServiceHost/nuget.config'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: |
     $(Build.SourcesDirectory)\MyService.ServiceHost\bin\debug\**\*.*

    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    artifactName: 'drop'

my nuget.config references

and a private feed in https://pkgs.dev.azure.com

[Update]

I tried adding preserveTimestamp: True to the CopyFiles@2 task but it made no difference

- task: CopyFiles@2
  displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: |
     $(Build.SourcesDirectory)\MyService.ServiceHost\bin\debug\**\*.*
    TargetFolder: '$(build.artifactstagingdirectory)'
    preserveTimestamp: True

[Update]

Leo advises a work around. However I am wondering how to unzip the file to release Currently my release pipeline contains

copy C:\azagent\A2\_work\r1\a\_PreMyFolder\drop\MyService.ServiceHost\bin\Debug\*.* "C:\Program Files (x86)\MyCompany\MyService Service"

Solution

  • Why does Azure Devops change the date on dlls downloaded from Nuget?

    That because the default value of the preserveTimestamp option is False in the Copy Files task.

    - task: CopyFiles@2
      inputs:
        #sourceFolder: # Optional
        #contents: '**' 
        targetFolder: 
        #preserveTimestamp: false # Optional
    

    To resolve this issue, you just need change the value to True.

    - task: CopyFiles@2
      inputs:
      sourceFolder:
      contents: '**' 
      targetFolder: 
      preserveTimestamp: True
    

    Update:

    I tried adding preserveTimestamp: True to the CopyFiles@2 task but it made no difference

    When I first tested this issue, I found that the copy task would modify the Timestamp of the file. This is indeed the case. And found a solution using option preserveTimestamp. I thought this was the whole issue until Kirsten Greed replied to me that this solution did not work.

    I had to test the issue again and found that the PublishBuildArtifacts task would also modify the Timestamp of the file, but there is no such preserveTimestamp option like copy task. We could found some similar thread here and here, but none of them gives a solution/workaround.

    The workaround I currently think of is that you could try to Bundle the artifacts in a compressed zip file, then unzip it when you use it.

    So, I use the Archive files instead of the copy task:

    - task: ArchiveFiles@2
    
      displayName: 'Archive $(Build.SourcesDirectory)\TestSample\TestSample\bin\Debug'
    
      inputs:
    
        rootFolderOrFile: '$(Build.SourcesDirectory)\TestSample\TestSample\bin\Debug'
    
        archiveFile: '$(Build.ArtifactStagingDirectory)/Test.zip'
    

    Then publish this zip file as artifact:

    - task: PublishBuildArtifacts@1
    
      displayName: 'Publish Artifact: drop'
    

    Now, I could keep the Timestamp for the files:

    enter image description here

    Hope this helps.