Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start on MS-Build

Tags:

msbuild

I wish to start using MS-Build. I have lots of projects which I build manually (from Visual Studio) as of now. I want to automate build process and preferably from a machine onto which I don't wish to install Visual Studio. I started reading about MS-Build on MSDN. But I am yet to get a step by step guidance where to start and how to do. My questions are like:

  1. How can I start MS-Build? Is there any download-able?
  2. What is the first step?
  3. How to create an MS-Build script?

And a lot similar questions. Can somebody guide me?

like image 780
Kangkan Avatar asked Jul 27 '10 09:07

Kangkan


People also ask

Which is the initial step needed when using the MSBuild at the command prompt?

MSBuild enables developers to consider command prompt simply. For this, the first step to perform is passing a project file to the .exe environment. This file must be either defined with the options of the command line specifying the operations.

How do I register for Microsoft build?

If you would like to invite someone else to watch a session, please ask them to register for free at https://register.build.microsoft.com to participate in Microsoft Build. Note that it may take a few minutes for their registration to become fully active, so encourage them to register early!

How do I get MSBuild path?

For example, the path to MSBuild.exe installed with Visual Studio 2019 Community is C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe You can also use the following PowerShell module to locate MSBuild: vssetup.


1 Answers

MS Build comes with the .NET Framework itself and the executable (msbuild.exe) is located in the .NET-framework directory, something like (depending on version):

  • C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
  • C:\WINDOWS\Microsoft.NET\Framework\v3.5
  • C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

(The right version is also in %path% when using the "Visual Studio command prompt" from the start menu.)

MsBuild files are xml-files. You can start by making a new text file, lets say "c:\myscript.msbuild", and copy-paste this to the file:

<Project DefaultTargets="MyTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="MyTarget">
    <Message Text="Hello world!" Importance="high"/>
  </Target>
</Project>

Then go to command prompt and type:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe c:\myscript.msbuild

That is a good start. :)

Then you can customize the targets and properties. Second example:

<Project DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(MyCondition)' == 'x'" >
    <MyProperty>World2</MyProperty>
  </PropertyGroup>
  <Target Name="MyTarget">
    <Message Text="Hello" Importance="high"/>
    <Message Text="$(MyProperty)" Importance="high"/>
  </Target>
  <Target Name="MyTarget2">
  </Target>
  <Target Name="All">
     <CallTarget Targets="MyTarget" />
     <CallTarget Targets="MyTarget2" />
  </Target>
</Project>

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe c:\myscript.msbuild /target:mytarget /property:MyCondition=x

You can have also build files inside build-files.

<Project DefaultTargets="MyTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="MyExternalProperties.msbuild"/>
  <Target Name="MyTarget">
    <Exec Command="echo Hello world 3"/>
  </Target>
</Project>
like image 66
2 revs, 2 users 99% Avatar answered Dec 31 '22 14:12

2 revs, 2 users 99%