Build Events is still useful in our actual project. For example, project A does not directly reference Project B, but the dll file of Project B is required in the runtime environment to reflect the object, in this case, we can copy the dll file corresponding to B to the Bin directory of Project A using the doscommand in Build Event of Project B. Some basic knowledge records about Build Envents are as follows:
1. VS Build events input:
Enter the DOS batch processing command in command lines. When vs is compiled, it is automatically executed before (Pre-Build) or after (Post-Build) compilation.
2. doscommand.
Now that we know that VS processes the commands in Build events as DOS batch processing commands, we can use the doscommand to customize our compilation process.
For example:
copy "$(ProjectDir)*.dll" "$(TargetDir)*.dll"
This command copies the ddl file under $ (ProjectDir) to the $ (TargetDir) directory.
If you want to copy a directory together, for example:
xcopy "$(ProjectDir)data\*.dll" "$(TargetDir)data\*.dll/s"
3. Batch Processing
Batch Processing is to put multiple DOS commands together.
As follows:
IF NOT EXIST "$(TargetDir)data" (MD "$(TargetDir)data")copy "$(ProjectDir)data\*.dll" "$(TargetDir)data\*.dll"
In this example, check whether the directory $ (TargetDir) data exists. If not, create the $ (TargetDir) data directory and copy the file.
Echo, @, call, pause, and rem are the most common commands for batch processing files. Let's talk about the special commands for batch processing.
Common special commands: if, goto, choice,. Maybe they are more suitable for scripting.
I. if
1. if [not] "parameter" = "string" command to be executed
If the parameter is equal to the specified string, the condition is true. Run the command. Otherwise, run the next sentence.
Example: if "% 1" = "a" format:
2. if [not] exist [path \] command to be executed in the file name
If a specified file exists, the condition is true. Run the command. Otherwise, run the next sentence.
For example, if exist c: \ config. sys type c: \ config. sys
Indicates that if the c: \ config. sys file exists, its content is displayed.
3. if errorlevel <number> command to be executed
Many DOS Programs return a numeric value to indicate the result (or status) of the program running after the execution ends. The if errorlevel command can be used to determine the return value of the program, different commands are executed based on different return values (the return values must be sorted in ascending order ). If the return value is equal to the specified number, the condition is true. Run the command. Otherwise, run the next sentence.
For example, if errorlevel 2 goto x2
Ii. goto
For example:
goto end :end echo this is the end
The label is defined by ": string". The row where the label is located is not executed.
3. choice
Note: choice commands are external commands provided by DOS or Windows. the syntax of choice commands of different versions is slightly different. Use choice /? View usage.
Choice command syntax (this syntax is the syntax of the choice command in Windows 2003, the syntax of choice in other versions is similar to this ):
CHOICE [/C choices] [/N] [/CS] [/T timeout/D choice] [/M text]
Description:
This tool allows you to select a project from the selection list and return the index of the selected project.
Parameter List:
/C choices specifies the list of options to be created. The default list is "YN ".
/N hide the Option List at the prompt. The preceding message is displayed, and the option is still enabled.
/CS allows you to select the case sensitivity option. By default, this tool is case-insensitive.
/T timeout specifies the number of seconds before the default value is set. The acceptable value ranges from 0 to 9999. If 0 is specified, there will be no pause. the default option is
Select.
/D choice: Specify the default option after nnnn seconds. The characters must be in the selection of a group specified by the/C option, and the/T must be used to specify the nnnn.
/M text specifies the message to be displayed before the prompt. If not specified, only the prompt is displayed.
/? Displays help messages.
Note:
The ERRORLEVEL environment variable is set to the key index selected from the selected set. Returns 1 for the first choice listed, 2 for the second choice, and so on. If the key you press is not a valid choice, the tool generates a warning. If the tool detects an error, it returns the ERRORLEVEL value of 255. If you press Ctrl + Break or Ctrl + C, the tool returns the ERRORLEVEL value of 0. When the ERRORLEVEL parameter is used in a batch program, the parameters are sorted in descending order.
IV.
Syntax:
Execute a specific command on each file in a group of files.
FOR % variable IN (set) DO command [command-parameters]
% Variable specifies a single letter replaceable parameter.
(Set) specifies one or more files. Wildcard characters can be used.
Command specifies the command executed on each file.
Command-parameters specifies a parameter or command line switch for a specific command.
For example, a batch file contains one row:
For % c in (*. bat *. txt) do type % c
The command line displays the contents of all files with the bat and txt extensions in the current directory.