環境: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中使用當前工作項目生成目錄