开发者

How to start on MS-Build

开发者 https://www.devze.com 2023-01-09 05:13 出处:网络
I wish to start using MS-Build. I have lots of projects which I build manually (开发者_StackOverflowfrom Visual Studio) as of now. I want to automate build process and preferably from a machine onto w

I wish to start using MS-Build. I have lots of projects which I build manually (开发者_StackOverflowfrom 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?


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>


MSBuild is similar to other build products like NAnt (just in case you've used one of those), but it is still different in a few respects.

Here is a good start page on MSDN. There are a truckload of different MSBuild task libraries released under various licences, most that i have seen are completely free to use and come with source code. Probably the two biggest are:

  • the open source MSBuild Community Tasks Project
  • the SDC Tasks Library on codeplex

Other good places to get info:

  • the MSBuild team blog
  • MSBuild Book
  • the blog of Sayed Ibrahim Hashimi (who is incredibly knowledgeable about the product but didn't work for MS until just recently). He also hangs out here on SO and may stumble across this question.

That should be enough to get started. If you can't find a task to do what you want, just write it yourseld - it is very easy.

0

精彩评论

暂无评论...
验证码 换一张
取 消