[Learn Note] MSBuild

1 Basic definitions

Key paired attribute / value corresponding to:

Environment variables defined in the project file itself using the / p passed to the command line parameters msbuild.exe

2

<Item Type="FilesToCompile" Include="file1.cs"/>  
<Item Type="FilesToCompile" Include="file2.cs"/>  
<Item Type="FilesToCompile" Include="file3.cs"/>
<Item Type="FilesToCompile" Include="*.cs"/>
<Item Type="FilesToCompile" Include="file1.cs;file2.cs;file3.cs" />
<Item Type="FilesToCompile" Include="*.cs" Exclude="Bad*.cs"/>

3 Tasks and Properties

Items can be used as input to the task. Corresponding XML Task element has a mandatory attribute: its Name property. You tell the engine of the kind of task to be performed for the value of the property will be set. MSBuild provides several readily available tasks, such as Copy, Csc, Exec, MakeDir, MSBuild, ResGen and Vbc.

<Item Type="FilesToCompile" Include="*.cs"/>  

<Target Name="BuildHelloWorldExecutable">
   <Task 
      Name="csc" 
      Sources="@(FilesToCompile)"
      OutputAssembly="HelloWorld.exe"
      TargetType="exe"
   />
</Target>
<Project>
   <Property 
      ExecutableName="HelloWorld" 
   />
   <Property 
      OutputPath="bin" 
   />

   <Item 
      Type="FilesToCompile" 
      Include="*.cs"
   />  

   <Target Name="BuildHelloWorldExecutable">
      <Task
         Name="MakeDir"
         Directories="$(OutputPath)"
      />
      <Task 
         Name="csc" 
         Sources="@(FilesToCompile)"  
         OutputAssembly="$(OutputPath)\$(ExecutableName).exe"
         TargetType="exe"
      />
   </Target>
</Project>

4 using the conditions are selected

<PropertyGroup Condition="'$(Configuration)'=='DEBUG'">
   <Property OutputPath="bin\debug" />
   ...
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='RELEASE'">
   <Property OutputPath="bin\release" />
   ...
</PropertyGroup>

5 Summary

Attributes are specified input parameters, the task is the actual process, belonging to a specific target

Visual Studio MSBuild can change the settings to understand the process of compiling the Options-> Projects and Solutions-> Build and Run-> MSBuild ...

Task is the basic building block for MSBuild. Target task specific order together. Its Name is the only mandatory attribute, because you need to be able to use the command line / t switch passes the property, or transfer the property in Project XML root node DefaultTargets property, so as to know the MSBuild tasks to be performed. In the project file, define the order of Tasks element is very important, because MSBuild each execution of a task for a given target.

6 Reference:

6.1 msdn
6.2 MSBuild Overview

By POST: Jalen Wang ( please indicate the source )

Reproduced in: https: //www.cnblogs.com/jalenwang/archive/2012/02/15/2353151.html

Guess you like

Origin blog.csdn.net/weixin_33968104/article/details/93414595