The compilation process for MSBuild is actually defined by a series of targets files, and when we perform build, batch build, and cleanup commands in the IDE, VS finds the corresponding task for those commands and executes it, let's analyze the process one at a time.
When you perform a build operation, MSBuild executes a task called "Build", which is defined in the targets file:
< Target
Name= "Build"
Condition= " ' $ (_invalidconfigurationwarning) '! = ' true ' "
dependsontargets= "$ (builddependson)"
Returns= "@ (Managedtargetpath); @ (Winmdfullpath)" >
< ItemGroup >
< Managedtargetpath Include =" $ (TargetPath) " Condition =" ' $ (managedassembly) ' = = ' true ' "/>
</ ItemGroup >
</ Target >
Here the BuildDependsOn is defined as:
< BuildDependsOn >
_prepareforbuild;
$ (buildsteps);
Afterbuild;
Finalizebuildstatus;
</ BuildDependsOn >
Expanding the Buildsteps:
< buildsteps Condition =" ' $ (buildsteps) ' = = ' ">
Resolvereferences;
Prepareforbuild;
Initializebuildstatus;
Buildgeneratesources;
Buildcompile;
Buildlink;
</ buildsteps >
This means that MSBuild will perform these tasks in turn:
_prepareforbuild;
Resolvereferences;
Prepareforbuild;
Initializebuildstatus;
Buildgeneratesources;
Buildcompile;
Buildlink;
Afterbuild;
Finalizebuildstatus;
But when our project was compiled with Makefile, we didn't have to let MSBuild control the whole process, because the process was already done in makefile, and we just had to reload the build as a task.
< Target
Name= "Build"
Condition= " ' $ (gnuprojecttype) ' = = ' UBoot ' or ' $ (gnuprojecttype) ' = = ' Linuxkernel ' or ' $ (gnuprojecttype) ' = = ' Linuxmakeapp ' "
>
< Embedlinuxmaketask
TargetName= "Build"
projectdir= "$ (projectdir)"
hostip= "$ (host_ip)"
hostuser= "$ (host_user)"
hostpasswd= "$ (host_passwd)"
Python2= "$ (python2_exe)"
pythonfile= "$ (pythonfile)"
/>
</ Target >
Of course, you need to tell Msbuild,embedlinuxmaketask where this task is before this:
< UsingTask TaskName =" Embedlinuxmaketask " assemblyfile =" EmbedLinux.dll "/>
This way, when compiling uboot, kernels, or applications that use Makefile, MSBuild will automate the task of Embedlinuxmaketask defined in EmbedLinux.dll!!
In the implementation of this task, we will execute the script specified by Pythonfile and redirect the output of this script to the Compile Information Output window of vs. This script is part of the project file and needs to be done with the compile and error message conversion functions. The SSH login operation is a generic operation that is placed in the implementation code of the task.
The Embedlinuxmaketask execution process is:
? Load Python2.exe
? Write environment variables in VS in Python
? Defining the behavior of the default compilation and information transformations
? Loads the specified compilation script in the project, overwriting the default behavior
? Start a logon operation
? Performs a compile operation to complete the conversion of the error message during the compilation process
? Returns the result of make
Application of Vs2012 in Linux development (6): Rewriting the build process of the Makefile project