仅在源较新(无论大小)的情况下,才进行MSBuild复制任务的复制 [英] make an MSBuild Copy Task only copy if the source is newer regardless of size

查看:72
本文介绍了仅在源较新(无论大小)的情况下,才进行MSBuild复制任务的复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译EXE时,我当前正在使用msbuild文件将某些文件复制到公共文档文件夹中.我当前的脚本包括:

I'm currently using an msbuild file to copy some files to the public documents folder when my EXE is compiled. My current script includes this:

<Target Name="DeployToPublicDocuments"
              Inputs="@(DeploymentItems)"
              Outputs="$(PublicDocumentsFolder)%(Path)\%(DeploymentItems.RecursiveDir)%(DeploymentItems.Filename)%(DeploymentItems.Extension)">
        <Copy SourceFiles="%(DeploymentItems.FullPath)"
            DestinationFiles="$(PublicDocumentsFolder)%(Path)\%(DeploymentItems.RecursiveDir)%(DeploymentItems.Filename)%(DeploymentItems.Extension)"
                Condition="!Exists('$(PublicDocumentsFolder)%(Path)\%(DeploymentItems.RecursiveDir)%(DeploymentItems.Filename)%(DeploymentItems.Extension)')" />

仅当目标不存在时,此代码才会复制.但是,如果源较新,我想替换目标.如何修改脚本以实现这一目标?我看到了SkipUnchangedFiles标志,但是它也比较文件大小以确定目标是否应该被覆盖.那不是我想要的.

This code only copies if the destination doesn't exist. However, I want to replace the destination if my source is newer. How do I modify my script to make that happen? I see the SkipUnchangedFiles flag, but it also compares file size to determine if the destination should be overwritten. That is not what I want.

推荐答案

您的副本的条件可以如下更改:

Your copy's conditional can be changed as follows:

    <Copy SourceFiles="%(DeploymentItems.FullPath)"
        DestinationFiles="$(PublicDocumentsFolder)%(Path)\%(RecursiveDir)%(Filename)%(DeploymentItems.Extension)"
            Condition="!Exists('$(PublicDocumentsFolder)%(Path)\%(RecursiveDir)%(Filename)%(DeploymentItems.Extension)') OR $([System.DateTime]::Parse('%(ModifiedTime)').Ticks) &gt; $([System.IO.File]::GetLastWriteTime('$(PublicDocumentsFolder)%(Path)\%(RecursiveDir)%(Filename)%(DeploymentItems.Extension)').Ticks)" />

%(ModifiedTime) =源文件的修改日期时间

%(ModifiedTime) = Modified Datetime of the source file

$([System.IO.File]::GetLastWriteTime($(PublicDocumentsFolder)%(Path)\%(RecursiveDir)%(Filename)%(DeploymentItems.Extension))) =目标文件的修改日期时间(如果存在)

$([System.IO.File]::GetLastWriteTime($(PublicDocumentsFolder)%(Path)\%(RecursiveDir)%(Filename)%(DeploymentItems.Extension))) = Modified Datetime of the destination file, if it exists

让我知道这是否有效,没有进行测试.

Let me know if this works or not, did not test.

这篇关于仅在源较新(无论大小)的情况下,才进行MSBuild复制任务的复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆