VS 2012:构建后xcopy错误2 [英] VS 2012: Post Build xcopy error 2

查看:761
本文介绍了VS 2012:构建后xcopy错误2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让VS将在构建过程之后创建的.lib文件复制到特定文件夹. 因此,我进入了项目配置,构建后事件,并输入了以下命令:

i want to make VS copy the .lib-file it created after the build process to a specific folder. So i went to the project config, post-build event, and entered the following command:

if exist $(TargetPath)
xcopy "$(TargetPath)" "C:\Users\Incubbus\Documents\Visual Studio 2010\My Libraries\z.lib" /Y

但是,如果我单击"build"后收到以下错误,则会导致复制失败,而不是复制:

But instead of copying the process fails after i click "build" and i receive the following error:

错误MSB3073:命令如果存在" C:\ Users \ Incubbus \ Documents \ Visual Studio 2010 \ My 库\ MyNetWorkProject \ Debug \ IncNetworkLibD.lib xcopy "C:\ Users \ Incubbus \ Documents \ Visual Studio 2010 \ My 库\ MyNetWorkProject \ Debug \ IncNetworkLibD.lib" "C:\ Users \ Incubbus \ Documents \ Visual Studio 2010 \ My Libraries \ z.lib"/Y

error MSB3073: The command "if exist C:\Users\Incubbus\Documents\Visual Studio 2010\My Libraries\MyNetWorkProject\Debug\IncNetworkLibD.lib xcopy "C:\Users\Incubbus\Documents\Visual Studio 2010\My Libraries\MyNetWorkProject\Debug\IncNetworkLibD.lib" "C:\Users\Incubbus\Documents\Visual Studio 2010\My Libraries\z.lib" /Y

:VCEnd"以代码2退出.

:VCEnd" exited with code 2.

我也想知道错误消息的命令字符串中的:VCEnd<-也许这是原因吗?如何解决这个问题?

I am also wondering about the :VCEnd in the command-string of the error message <- Maybe this is the reason? How to get this solved?

任何帮助和提示都会很愉快:)...

Any help and hints would be happily consumed :)...

部分解决方案:

partial solution:

编辑:当xcopy询问这是文件还是目录时,重命名部分(从Inc.libz.lib)看起来很麻烦.当我只将原始命名的文件复制到目录而不是复制已重命名的文件时,.it就起作用了

EDIT: it looks like the renaming part (Inc.lib to z.lib) makes trouble, when xcopy asks whether this is a file or a directory...it works when i just copy the originally named file to a directory instead of copying renamed

推荐答案

指定目标是文件还是目录 如果目标"不包含现有目录并且不以反斜杠(\)结尾,则会出现以下消息:

Specifying whether Destination is a file or directory If Destination does not contain an existing directory and does not end with a backslash (\), the following message appears:

Does destination specify a file name 
or directory name on the target 
(F = file, D = directory)? 

如果要将一个或多个文件复制到文件,请按F.如果要将文件复制到目录,请按D.

您可以通过使用/i命令行选项来禁止显示此消息,如果源是多个文件或目录,则该选项使xcopy假定目标是目录.

You can suppress this message by using the /i command-line option, which causes xcopy to assume that the destination is a directory if the source is more than one file or a directory.

您需要相反的选择,但没有这种切换.

You need the opposite, but there is no such switch.

此处提出了解决方案: https://stackoverflow.com/a/4283533/532647 .

The solution is proposed here: https://stackoverflow.com/a/4283533/532647.

建议在xcopy命令前加上echo f |前缀,这基本上可以执行以下操作:它模拟用户在xcopy询问时按f键.

It is suggested to prepend the xcopy command with echo f | prefix, which basically does the following: it simulates a user pressing f key when xcopy asks.

因此您的命令应如下所示:

So your command should look like:

if exist $(TargetPath)
echo f | xcopy "$(TargetPath)" "C:\Users\Incubbus\Documents\Visual Studio 2010\My Libraries\z.lib" /Y

运算符|只是将echo f(== f)的输出传递到xcopy命令中,并在适当时进行读取.有关输出重定向的更多信息,请参见: http://ss64.com/nt/syntax-redirection.html .

Operator | just pipes the output of echo f (== f) into xcopy command and it is read when appropriate. More information about output redirection here: http://ss64.com/nt/syntax-redirection.html.

更新: 正如Govert 指出的那样,这种黑客行为在Windows的本地化版本. 但是,另一种方法也可以使用:

UPDATE: As Govert points out, this hack won't work under a localized version of Windows. However, another hack will work:

xcopy D:\file.zip c:\renamedFile.zip*

在目标文件名后加上星号*会使xcopy不会询问目标文件是文件还是目录.

Appending destination file name with an asterisk * makes xcopy not ask whether destination is a file or a directory.

这篇关于VS 2012:构建后xcopy错误2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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