Monday, July 8, 2019

MSBuild project constructs

MSBuild project constructs:
---------------------

MSBuild Project Files
Targets
Tasks
Properties
Items


Sample.msbuild
-------------------


<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Byeworld" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 
 <PropertyGroup>
  <PicsPath>c:\temp\pics\*.jpg</PicsPath>
 </PropertyGroup>
 
 <ItemGroup>
  <Pics Include="$(PicsPath)" />
 </ItemGroup>
 
 <Target Name="ListPics">
  <Message Text="@(Pics)"/>
  <Message Text="@(Pics->'%(ModifiedTime)')"/>
 </Target>
 
 <Target Name="Helloworld">
  <Message Text="Hello World!1"/>
  <Message Text="Hello World!2"/>
 </Target>
 <Target Name="Byeworld">
  <Message Text="Bye World!1" Importance="low"/>
  <Message Text="Bye World!2" Importance="high"/>
 </Target>
</Project>


MSBuild.exe locations:
"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
"c:\windows\Mirosoft.NET\Framework\v4.0.30319" --search for msbuild here.And the strucure is in the xsd file, where the namespaces will be defined, in the msbuild folder.

running:
---------------
msbuild sample.msbuild --runs all the targets.
Will be ran first target as defined in the order.

to run a particular target,commandline parameter:
msbuild sample.msbuild /target:HelloWorld
Or set the target to be ran in the DefaultTargets attribute of project in the .msbuild file.
<Project DefaultTargets="Byeworld">
Preference will be given to the command line argument than the msbuild attribute,if both are defined.

you can pass multiple commadn line arguments by creating a response file and passing that file running.

sample_response.rsp
---------------
/target:Helloworld
/target:Helloworld,Byeworld
/v:low


msbuild sample.msbuild @sample_response.rsp


All tasks like (Message) in assembly,object browser-.NET Framework 4-Microsoft.Build.Tasks.v4.0-Microsoft.Build.Tasks-many types are defined here.
Say Message---here it implements ITask,which contains execute() method.the properties are used as attributes in the task.like here, Text,Importance(values:high,normal,low),based on importance, the color is blue,grey and not printed at all for console output string of Message.

We can set logging in rsp file also for all tasks(/v:normal,low,diagnostic).

For storing data in the msbuild file and access variables:
<PropertyGroup>
<Name>Homer</Name>
<FullName>Homer</FullName>
</PropertGroup>

<Target Name="Byeworld">
<Message Text="Bye World! $(FullName)" Importance="low"/>
</Target>

Or can be passed as command line parameter.
msbuild sample.msbuild @sample_response.rsp /p:Name=Lisa

there are some properties are there by default called as Reserved properties.

which are visible if we keep /v:diagnostic

itemgroup to access list of files and their content.






No comments:

Post a Comment