在VS中生成后拷贝文件

环境:win7_64旗舰版,VS2013

工作项目中,一般会使用第三方库,当修改并重新编译第三方库后,需要将DLL文件拷贝到工作项目下的生成目录中,每次手动拷贝比较繁琐,VS提供自定义生成事件,允许我们在生成前、链接时、生成后执行命令。

一、新建copy_file.bat文件

echo copy_dll.bat
if %Configuration%==Debug (
    echo -^> copy "%third_part%\bin\" to "%SolutionDir%%Configuration%\"
    copy /Y %third_part%\bin\test_d.dll %SolutionDir%%Configuration%\ >nul
) else if %Configuration%==Release (
    echo -^> copy "%third_part%\bin\" to "%SolutionDir%%Configuration%\"
    copy /Y %third_part%\bin\test.dll %SolutionDir%%Configuration%\ >nul
) else (
    echo Error
)

其中"%third_part%\bin\"为第三方库DLL目录,"%SolutionDir%%Configuration%\"当前工作项目生成目录

二、VS项目设置

打开 项目属性页 -> 配置属性 -> 生成事件 -> 后期生成事件

在命令行中输入:

set SolutionDir=$(SolutionDir)
set Configuration=$(Configuration)
copy_file.bat

我们将当前工作项目中的环境变量设置到命令行中,以便在copy_file.bat中使用当前工作项目生成目录

posted on 2016-02-21 20:19  dchao  阅读(3990)  评论(0编辑  收藏  举报

导航