Bra*_*non 10 c# msbuild msbuild-task file-copying
我正在编译时,我正在使用msbuild文件将一些文件复制到公共文档文件夹.我目前的脚本包括:
<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)')" />
Run Code Online (Sandbox Code Playgroud)
此代码仅在目标不存在时复制.但是,如果我的源更新,我想替换目标.如何修改我的脚本以实现这一目标?我看到SkipUnchangedFiles标志,但它也比较文件大小以确定是否应覆盖目标.那不是我想要的.
小智 14
您的副本的条件可以更改如下:
<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) > $([System.IO.File]::GetLastWriteTime('$(PublicDocumentsFolder)%(Path)\%(RecursiveDir)%(Filename)%(DeploymentItems.Extension)').Ticks)" />
Run Code Online (Sandbox Code Playgroud)
%(ModifiedTime) =源文件的修改日期时间
$([System.IO.File]::GetLastWriteTime($(PublicDocumentsFolder)%(Path)\%(RecursiveDir)%(Filename)%(DeploymentItems.Extension))) =目标文件的修改日期时间(如果存在)
让我知道这是否有效,没有测试.
我想你可能误读了文档:
SkipUnchangedFiles
如果为true,则跳过在源和目标之间未更改的文件的复制.如果文件具有相同的大小和相同的上次修改时间,则复制任务会将文件视为未更改.
http://msdn.microsoft.com/en-us/library/vstudio/3e54c37h.aspx
| 归档时间: |
|
| 查看次数: |
6812 次 |
| 最近记录: |