it:ad:msbuild:howto:syntax

IT:AD:MSBuild:HowTo:Syntax


PropertyGroups used to group Configuration Switches/Properties.

  <?xml version="..."?>
  <Project>  
    <PropertyGroup>   
      <Configuration Condition="...">   
    </PropertyGroup>  
   </Project>
  

ItemGroups used to contain groups of items.

   
  <Project>
    ...
    <ItemGroup>
      <Reference Include="System.Core"/>
      ...
    </ItemGroup>
    <ItemGroup>
      <Compile Include="Program.cs"/>
      <Compile Include="Properties\AssemblyInfo.cs"/>
      ...
    </ItemGroup>
    ...
  </Project>

An import statement allows to pull in MSBuild code from other files. By Convention extension is either *.props (contain properties) or *.targets (contain target definitions)

<Project>
  ...
  <Import Project="$(MSBuiltToolsPath\Microsoft.CSharp.targets"/>
</Project>
   

A Target is sort of a Method/Subroutine, written in XML.

<Target Name="SomeName"> 
  <PropertyGroup>
    <MyProp>Hello World!</MyProp>
  </PropertyGroup>
  <!-- Use a Method -->
  <Message Text="$(MyProp)"/>
</Target>

The Build process's Main is defined by the Project element's @DefaultTargets attribute:

 <Project ToolsVersion="4.0" DefaultTargets="Build"  ...>
   ...
 </Project> 

The Build target is dfined in the default *.targets file. Like any target, it in turns invokes other Targets.

The build process's target can be set to:

//Run default well known Build Task:
msbuild Sample.csproj 
//Run default well known Rebuild:
msbuild Sample.csproj /t:Rebuild
//Run Clean then Build
msbuild Sample.csproj /t:Clean;Build
  • /home/skysigal/public_html/data/pages/it/ad/msbuild/howto/syntax.txt
  • Last modified: 2023/11/04 22:59
  • by 127.0.0.1