28

我在 Visual Studio 解决方案中有许多 Web 应用程序。

都有相同的后期构建命令:

xcopy "$(TargetDir)*.dll" "D:\Project\bin" /i /d /y

避免用旧文件替换新文件会很有用(例如,有人可能会不小心添加对旧版本 DLL 的引用)。

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

4

3 回答 3

31

在命令行输入“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开关的位置。

于 2011-07-13T20:25:15.100 回答
3

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

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

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

于 2020-01-07T08:30:17.337 回答
1

未经测试,但我对这类任务使用了类似的命令脚本。

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
于 2012-08-28T14:25:05.060 回答