[PE] Compile VS project through batch script command line

###Date: 2017/9/25

          Visual Studio IDE itself has the functions of compiling, linking, debugging and analysis, and is a very powerful software for code debugging and reading. However, it is usually more convenient to compile the VS project in the form of batch script for the generation of the library under the windows platform, and it is not necessary to open the VS software.

        Let's take Mpeg4's open source implementation of Xvid's project libxvidcore.sln as an example to sort out the general method of compiling VS projects through batch script command lines.

1. Compile the general template from the command line

@rem Description: Windows platform command line compilation script
@rem role: compile the VS project through the batch script command line
@echo off
@rem usage: build.bat Release/Debug Win32/x64
 

@rem set build_config="Debug|Win32"
@rem set build_config="Release|Win32"
@rem set build_config=$ALL

@rem current environment settings are only valid in this file
@setlocal
@rem "command line input parameters"
set build=%1
set platform=%2
set build_config="%build%|%platform%"

@echo %date% %time%  >build.log

@rem The path where the current script is located
@echo "build directory..."
@echo %~dp0
set build_root = %~dp0

@rem various files and paths
set VCVARS="%VS120COMNTOOLS%../../VC/vcvarsall.bat"
set DEVENV="%VS120COMNTOOLS%../IDE/devenv.exe"

@rem sets the solution path
set SOlUTION="%~dp0libxvidcore.sln"
@echo "Solution..."
@echo %SOLUTION%

@rem check file path configuration
if not exist %VCVARS% echo "VCVARS不存在!" &goto end
if not exist %DEVENV% echo "DEVENV不存在!" &goto end
if not exist %SOlUTION% echo "SOlUTION不存在!" &goto end

@rem delete output file
if exist build.log del build.log

@rem build environment configuration
@echo "Environment configuration..."
if %platform%=="Win32"  (
     echo "Windows 32-bit environment configuration..."
     call %VCVARS% x86)
   
if %platform%=="x64" (
	 echo "Windows 64-bit environment configuration..."
	 call %VCVARS% x86_amd64)

@echo build_config:%build_config%,please waiting

@echo "start compiling"
%DEVENV% %SOlUTION% /rebuild %build_config% /out build.log
rem notepad build.log
copy %~dp0bin\xvidcore.dll  %~dp0..\lib\
copy %~dp0bin\xvidcore.lib  %~dp0..\lib\


:end
@rem pause
@endlocal

This mainly involves the use of the devenv.exe command and the setting of the windows compilation environment (see http://blog.csdn.net/soaringlee_fighting/article/details/78043905 for details).

Second, the usage of Devenv.exe

devenv[solutionfile | projectfile | anyfile.ext] [switches]

The first argument to devenv is usually a solution file (.sln) or project file (.vcproj). You can also use any other file as the first argument if you want the file to be opened automatically in the editor. When you enter a project file, the IDE looks in the project file's parent directory for a .sln file with the same base name as the project file. If no such .sln file exists, the IDE will look for a single .sln file that references the project. If no such single .sln file exists, the IDE will create an unsaved solution with a default .sln filename with the same base name as the project file.

Command line compilation:

devenv solutionfile.sln /buildsolutionconfig [ /project projectnameorfile [ /projectconfig name ] ]

Command line switches available with devenv:

/Build

Generate a solution with the specified solution configuration or

project. For example "Debug". If multiple platforms may exist,

then the configuration name must be enclosed in quotes

and contains the platform name. For example "Debug|Win32".

/Clean

Delete build results.

/Command

Start the IDE and execute the command.

/Deploy

Build and deploy the specified build configuration.

/Edit

Open in a running instance of this application

Specify the file. If there is no running instance,

then starts a new instance with a simplified window layout.

/LCID

Sets the default language used in the IDE for the user interface.

/Log

Log IDE activity to the specified file for troubleshooting.

/NoVSIP

Disable the VSIP developer license key for VSIP testing.

/Out

Append the build log to the specified file.

/Project

Specifies the project to build, clean, or deploy.

Must be used with /Build, /Rebuild, /Clean or /Deploy.

/ProjectConfig

Rewrite the solution

The project configuration specified in configuration. For example "Debug". if possible

multiple platforms, the configuration name must be enclosed in quotes

and include the platform name. For example "Debug|Win32".

Must be used with /Project.

/Rebuild

Clean first, then build with specified configuration

solution or project.

/ ResetAddin

Removes commands and command UI associated with a specific add-in.

/ResetSettings

Restore IDE default settings, and can also reset to

The specified VSSettings file.

/ResetSkipPkgs

Clears all SkipLoading flags added to VSPackages.

/Run

Compile and run the specified solution.

/ RunExit

Compile and run the specified solution and close the IDE.

/SafeMode

Start the IDE in safe mode with the minimum number of windows loaded.

/Upgrade

Upgrade a project or solution and all projects within it.

and create backups of these files accordingly. About backup

For more information on the process, see

Help on the Visual Studio Conversion Wizard.


refer to:

http://blog.csdn.net/listener51/article/details/76039146



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325991149&siteId=291194637