fuzzelogic Solutions

October 20, 2010

MSBuild - build automation : part 2

Filed under: .net, c# — Tags: — admin @ 1:29 pm

Continuing on with MSBuild as a build automation system, there’s a few fundamentals to be aware of.

  • PropertyGroup : containing Properties. These are referenced using $(PropertyName) : from Microsoft: Properties are key/value pairs that can be used to configure builds. Properties are useful for passing values to tasks, evaluating in conditions, and storing values that will be referenced thoughout the project file.
  • ItemGroup: containing Items. These are referenced using @(ItemName) : from Microsoft: Items represent inputs into the build system that are grouped into item collections based on their user-defined collection names. These item collections can be used as parameters for tasks, which use the individual items contained in the collection to perform the steps of the build process.
  • Targets: These conain the Tasks to execute. : from Microsoft: Targets group tasks together in a particular order and allow sections of the build process to be called from the command line. Targets are often grouped into logical sections to allow for project file expansion and to increase readability. For example, one target may delete all files in the output directory to prepare for the build, while another compiles the inputs for the project and places them in the empty directory.
  • Task: The step to be executed/actioned. : from Microsoft: build platform needs the ability to execute any number of actions during the build process. MSBuild uses tasks to perform these actions. A task is a unit of executable code used by MSBuild to perform atomic build operations.

So lets put together what we have so far (from part 1), and put a basic build script together. Nothing too fancy just the standard hello world. A basic script that will output some text to the console window. First off, I usually create a batch file with the following in it :
%comspec% /k “”c:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat”" x86. This would allow us to run the msbuild file from our current location. Next off, Visual studio is about the best editor for the build file. It provides much needed intellisense support. You can use any text editor, Notepad, Notepad ++ etc.

So fire up the editor and churn out the bits below. First off, put in the xml declaration and Project node. Notice the DefaultTargets. This points to the Target that must be called to start off with. Next off, we add the Property group with  a single property. This will contain the text we want to output. Create the Target node and name it go. MsBuild offers a host of prebuild Tasks and one of them we will use is Message task.  Save this file in the same folder as the startup batch script. Call it helloworld.buildFile.

<?xml version=”1.0″?>
<Project xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″ DefaultTargets=”go”>
<PropertyGroup>
<text_to_print>Hello msbuild World .. </text_to_print>
</PropertyGroup>
<Target Name=”go” >
<Message Text =”$(text_to_print)” />
</Target>
</Project>

To run this, fire up the batch file (the one from above), then at the command prompt type in  msbuild helloworld.buildFile.

results from hello world

results from hello world

October 3, 2010

MSBuild - build automation : part 1

Filed under: .net, c#, projects — Tags: , , — admin @ 5:50 pm

Hi!.

I’m starting a series on build automation using msbuild. This will cover topics including the basics of msbuild, advanced topics using extensions, custom tasks and using msbuild as a deployment tool.

Why MSBuild?

Well, the simple answer. Its already there, its a build system maintained by Microsoft and keeps up to date with the latest version of .net.

Planning.

Like with everything else, for a robust build system to work, it takes some planning.

  • Project layout - this will allow us to traverse the directory structure.
  • Build requirements - Do we want to build in Debug/release both?? Do we want to run tests??
  • Naming convention - come up with a meaningful naming convention.

The Basics

Ok, so the basics of msbuild. MSBuild is a Microsoft build platform shipped with the .net framework. Version 3.5 of MSBuild, which is bundled together with .NET 3.5 (and Visual Studio 2008), allows .NET projects to be built for either 2.0, 3.0 or 3.5 .NET version support (so called “multi-targeting”).

It is possible to build Visual Studio projects and solutions without the Visual Studio IDE installed and MSBuild is available at no cost.

Its based on an XML syntax, so we start with ..

<?xml version=”1.0″ encoding=”utf-8″?> next we add in the project tag. This encloses all the targets, properties and items required for the build. In adition to the namespace declaration, there’s 3 additional attributes worth noting. InitialTargets, ToolsVersion and DefaultTargets.

Xmlns : Required attribute.The xmlns attribute must have the value of “http://schemas.microsoft.com/developer/msbuild/2003″.

ToolsVersion: sets a target .NET Framework version to build the project with.Optional attribute

DefaultTargets: the default target(s) to run. Optional attribute. If no default target is specified in either the DefaultTargets attribute or the MSBuild command line, the engine executes the first target in the project file after the Import elements have been evaluated.

InitialTargets:runs before the targets specified in the DefaultTargets Optional attribute

<Project  xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″ InitialTargets=”runs_before_the_default”
DefaultTargets=”start_the_build”>

When specifying targets you can seperate multiple targets using a semicolon. The project file contains Property Groups, Item Groups and Targets. Targets contain a collection of executable tasks.

In the next post we’ll put all this together on a typical project.

July 20, 2010

Annual Sponsor - Fly fishing

Filed under: isle of man — Tags: , , , — admin @ 12:44 am

Hi!
Just to let everyone know, Fuzzelogic solutions annual sponsored Fly fishing event kicks off this Sunday (25th July 2010). As usual its at the Clypse and Kerrowdhoo reserviors starting at 09:30 am.

This year there are some bumper prizes with over £700.00 worth up for grabs.

Registration should start around 9:00 am so be early to avoid disappointment..

Good luck and hope you can all make it!!

Thanks

Zak

May 29, 2010

VS 2010 - So far Top marks

Filed under: c# — admin @ 3:03 pm

Hi All!

Ok, I’ve started using Visual studio 2010. It’s great !!
I’ve not even got into the new 4.0 features fully yet. This is a real great IDE (so far). This a little unlearning which does not take long.

I’ll write  a full(er) review once I get through this. Some of the cool new features so far

  • Dockable tool-windows : these are free floating and don’t have to be in the main IDE - great for Multiple monitors
  • Zoom : In a code window, click ctrl + scroll your mouse wheel.
  • Highlight references: If the IDE detects other references on the same code page, it highlights it - you can navigate through them using ctrl+shift + (up/down) key..
  • Tabbed pages have the close button on the TAB !

There’s a bunch more…. I’ll update as I go along.. There’s also,

  • F# language included.
  • Entity Data Model : this is brilliant - Model first design. Now we can build the models before the database - it generates the DDL for the database schema

Take care!

Zak

May 17, 2010

Microsoft Region Info - Isle of Man

Filed under: Programming, Region Info, Windows, c#, isle of man — Tags: , , , , , — admin @ 3:10 pm

Hi All!

Microsoft does listen. Awhile back I posted an issue concerning the region info object in all versions of the .net framework upto 3.5 (http://fuzzelogicsolutions.com/wordpress/index.php/2009/06/07/ms-did-not-consider-the-isle-of-man/).

It seems Microsoft, does actually listen, and the Isle of man should be included in the Windows database.

RegionInfo

From Micorsoft

Hope that helps!!
Take care!
Zak

Older Posts »

Powered by WordPress