Visual studio 如何使用xcopy仅复制更新的文件?

Visual studio 如何使用xcopy仅复制更新的文件?,visual-studio,xcopy,post-build-event,Visual Studio,Xcopy,Post Build Event,我在VisualStudio解决方案中有许多web应用程序 都具有相同的生成后命令: xcopy "$(TargetDir)*.dll" "D:\Project\bin" /i /d /y 避免用旧文件替换新文件(例如,有人可能会意外地添加对旧版本DLL的引用)会很有用 如何使用xcopy仅用Visual Studio生成的较新DLL文件替换旧文件?在命令行键入“help xcopy”: /D:m-d-y Copies files changed on or after the spe

我在VisualStudio解决方案中有许多web应用程序

都具有相同的生成后命令:

xcopy "$(TargetDir)*.dll" "D:\Project\bin" /i /d /y
避免用旧文件替换新文件(例如,有人可能会意外地添加对旧版本DLL的引用)会很有用

如何使用xcopy仅用Visual Studio生成的较新DLL文件替换旧文件?

在命令行键入“help xcopy”:

/D:m-d-y     Copies files changed on or after the specified date.
             If no date is given, copies only those files whose
             source time is newer than the destination time.

因此,您已经在使用xcopy仅将旧文件替换为新文件。如果没有发生这种情况,您可能必须交换
/i
/d
开关的位置。

未测试,但我使用类似的命令脚本执行此类任务

set DIR_DEST=D:\Project\bin
pushd "$(TargetDir)"

::
:: Move Files matching pattern and delete them
::
for %%g in (*.dll) do (xcopy "%%g" "%DIR_DEST%" /D /Y & del "%%g")

::
:: Move Files matching pattern
::
:: for %%g in (*.dll) do (xcopy "%%g" "%DIR_DEST%" /D /Y )

popd

用户按照命令将所有新的和修改过的文件从源复制到目标

xcopy c:\source d:\destination/d/I/E/Y

/D检查是否存在任何修改的文件
/I如果目标不存在并复制多个文件,则假定目标必须是目录。
/E复制目录和子目录
/Y以抑制任何超写提示。