其他分享
首页 > 其他分享> > VS 使用cmd命令编译

VS 使用cmd命令编译

作者:互联网

参考资源链接
build.bat 文件

@echo off

rem -------------------------------------------------------- 
rem -- Function section starts below here 
rem --------------------------------------------------------

rem _solution_file是解决方案名称,log是编译日志文件
rem 这个bat示例如下:

rem setlocal
set vcvars="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
set _solution_file="%~dp0/CL200A_Api_x86_x64_C+11_dll.sln"
echo %_solution_file%

call .\find.bat sln
set _solution_file=%FIND_RET%

echo %_solution_file%

pause
goto:eof

set build=%1
set platform=%2
set build_config="%build%|%platform%"
echo build_config = %build_config%
rem set compile log
set _log="%~dp0CompileResultsAll.log"
rem del build log if the log is not empty
if exist %_log% (del %_log%)
rem 当前脚本所在路径
set build_root = %~dp0
set work_path=%~dp0/NFMidWare
rem vcvarsall.bat所在的路径:
call %vcvars% x64
echo "开始所有目录编译"
rem 设置解决方案的路径
@echo %~dp0

call:buildPro "CL200A_Api_x86_x64_C+11_dll"
pause
goto:eof

::-------------------------------------------------------- 
::-- Function section starts below here 
::-------------------------------------------------------- 
:buildPro    - here starts my function identified by it's label 
devenv %_solution_file%  /build %build_config% /Project %1 /Out %_log%
if not %errorlevel% == 0 echo %_solution_file% failed!   Error: %errorlevel% >>%_log%
if %errorlevel% == 0 echo %_solution_file% compiled successful >>%_log%
::If compile failed stop processing:
if not %errorlevel% == 0 (
	goto:eof
)
echo [%DATE% %Time%] %1 编译完成
goto:eof
echo "结束全编译"

:: 可以通过遍历某个目录,获取工程文件名,在传入上面所描述的函数中 获取工程名方法如下:
@echo off
rem 文件夹路径
set path=".\Server"
for /r %path% %%f in (*.vcxproj) do (
rem 完整路径文件名
 rem echo %%f
rem 文件名
 echo %%~nf)
rem 文件扩展名
rem echo %%~xf)

find.bat 文件

@echo off

set FIND_RET=""
set FIND_PARAM="*.%1"
rem 文件夹路径
set path=".\"
for /r %path% %%f in (%FIND_PARAM%) do (
rem 完整路径文件名
 rem echo %%f
rem 文件名
echo %%~nf
set FIND_RET=%%~nf%%~xf
rem 文件扩展名
rem echo %%~xf
)

echo FIND_RET = %FIND_RET%

标签:set,%%,cmd,echo,编译,%_,VS,build,rem
来源: https://blog.csdn.net/qq_37377257/article/details/121409980