Monthly Archive for September, 2007

MSBuild Sleep Task

Do you know how to pause a MS Build task? Here I’d like to give you an option by writing a simple task which can be included in a project file.

First create a new C# Class Library Solution called “SleepTask”, Copy & Paste the following C# code and compile the entire solution. But don’t forget to add the Microsoft.Build.Framework and Microsoft.Build.Utilities references in your project.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Threading;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
 
namespace SleepTask
{
    public class Sleep : Task
    {
        public override bool Execute()
        {
            Thread.Sleep(Timeout);
            return true;
        }
 
        private Int32 timeout;
        public Int32 Timeout
        {
            get { return timeout; }
            set { timeout = value; }
        }
    }
}

Now write a new MS Build project file (e.g. Project.xml) and Copy & Paste the following XML tags. With the “Timeout” attribute you can define the timeout in milliseconds for the SleepTask (e.g. 3 seconds). Before running the project you have to copy the SleepTask.dll assembly into the folder of your Project.xml file, of course.

1
2
3
4
5
6
7
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
  DefaultTargets="Default">
  <UsingTask AssemblyFile="SleepTask.dll" TaskName="Sleep" />
  <Target Name="Default">
    <Sleep Timeout="3000" />
  </Target>
</Project>

Finally run your MS Build task by typing the following command (use the Visual Studio Command Prompt) and see that the task is paused because of the defined timeout.

MSBuild Project.xml

So oder So?

Ich möchte mich Uwe’s “So oder so”?-Artikel anschließen und hier eine Frage stellen, die uns ebenfalls schon lange beschäftigt: Welche Seite eines (Sesam-)Knäckebrotes sollte man mit Butter bestreichen? Wie ist es richtig – die Seite mit Sesam oder die Seite ohne Sesam?

So:
Knäckebrot 1

… oder so?:
Knäckebrot 2

Fotos von der Nordseeküste 2007

Dieses Album ist geschützt. Bei Interesse schreib’ mir einfach eine E-Mail.