Custom Build Number In Team Build

Many users want to modify the default build number of Team System Team Build which looks like: <Build-Type-Name>_<Date>.XXX.

You can change it by writing a custom task and call it in the BuildNumberOverrideTarget target of the MSBuild file. In this example the task will generate a unique build number based on current time:

using System;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;


namespace MaorDavidBlog.Samples.MSBuild
{
public class BuildNameGenerator:Task
{

private string _buildName;

public override bool Execute()

{
_buildName = DateTime.UtcNow.ToString();
return true;
}



[Output]
public string BuildName

{
get { return _buildName; }
}

}
}

The attribute “Output” indicates that BuildName property is output of the custom task.

Then, register the task in TFSBuild.proj file.

<!-- Add using task line just after import statement - - >
<UsingTask
TaskName="MaorDavidBlog.Samples.MSBuild.BuildNameGenerator"
AssemblyFile="$(MyCustomTasks)MaorDavidBlog.Samples.MSBuild.dll"/>



<! -- Override the target towards the end of proj file - - >
<Target Name = "BuildNumberOverrideTarget" >
<BuildNameGenerator>
<Output TaskParameter="BuildName"
PropertyName="BuildName"/>
</BuildNameGenerator>
</Target>

 

Next time you’ll execute your build, you’ll see your custom build name.

Copy WildCards With MSBuild

I got today hysterical message from a good friend that implementing in his company automatic build with Team System. The message was: "Maor, How can I copy wildcards With MSBuild? Please help!!!".

Okay. What you should do my dear friend is:

1. Create an item list if you have more than one file to copy. You can do it with the CreateItem task:

<CreateItem Include="$(MyDir)*.*">
<Output TaskParameter="Include" ItemName="MyFilesToCopy" />
</CreateItem>

2. Copy!

<Copy SourceFiles="@(MyFilesToCopy)" DesginationFolder="$(MyPutputDir)" />

3. Execute your build script.

Ah, by the way, if you want to recursively copy files using the <Copy> task, read this post from MSBuild Team Blog.

Enjoy!

Automatically Compare Data and Schema Using MSBuild and Data Dude

VSTS for DB Professionals (aka "Data Dude" or "VSDBPro") provides great tools for schema and data compare.

Like most Visual Studio-based project systems, the core tasks inside the VSDBPro project implemented as MSBuild tasks. The two core activities for Database Projects (.dbproj), “Build” and “Deploy” are implemented by two MSBuild tasks named “SqlBuildTask” and “SqlDeployTask.”

Sometimes, we also need to automate the schema and data compare processes. We can do it with new MSBuild dedicated tasks that shipped with Power Tools for Data Dude๐Ÿ˜ฆCurrently available for VSTS 2005)

  • SqlDataCompareTask: allows you to compare the content of tables within two databases from the command line using MSBuild
  • SqlSchemaCompareTask: allows you to compare schemas between two database from the command line using MSBuild

How should you use it?

First, install the Power Tools. Download from here. (notice that the power tools requires Data Dude Service Release 1 installed).

After you installed the power tools you can use the tasks in your MSBuild script.

Example:

  <!--Import the settings-->
<Import Project="$(MSBuildExtensionsPath)MicrosoftVisualStudiov8.0
TeamDataMicrosoft.VisualStudio.TeamSystem.Data.PowerTools.Tasks.targets"
/>

<Target Name ="DataCompare">
<SqlDataCompareTask
SourceConnectionString="Data Source=(.);Integrated Security=True;Pooling=False"
SourceDatabaseName="SourceDB"
TargetConnectionString="Data Source=(.);Integrated Security=True;Pooling=False"
TargetDatabaseName="TargetDB"
OutputPath = "$(temp)"
OutputFileName = "DataCompare.sql"/>
</Target>

Notice that the task does not allow you to compare against the project right now. Same way you can use the SqlSchemaCompareTask.

<Import Project="$(MSBuildExtensionsPath)MicrosoftVisualStudiov8.0
TeamDataMicrosoft.VisualStudio.TeamSystem.Data.PowerTools.Tasks.targets"
/>
<Target Name ="SchemaCompare">
<SqlSchemaCompareTask
SourceConnectionString="$(SourceConnectionString)"
SourceDatabaseName="$(TargetDatabase)"
TargetConnectionString="$(TargetConnectionString)"
TargetDatabaseName="$(TargetDatabase)"
OutputPath = "$(IntermediateOutputPath)"
OutputFileName = "$(TargetDatabase)SchemaCompare.sql"
IgnoreChecks ="true"
/>
</Target>

The properties exposed by the MSBuild tasks are documented via an accompanying XSD file located in:

%ProgramFiles%Microsoft Visual Studio 
8XmlSchemas1033MSBuildMicrosoft.VisualStudio.TeamSystem.Data.PowerTools.Tasks.xsd

How To: Build Non-MSBuild Projects with MSBuild

Building non-MSBuild projects is possible. For example you have to build VS2003, Installer, C++, Delphi projects etc. How can you do it? It’s simple.

The MSBuild has a built-in task: Exec task. This task calls cmd.exe instead of directly invoking a process and runs the specified program or command with the specified arguments. You can use it in order to build non-MSBuild projects.

For example, in order to build a Visual Studio 2003 Project you should modify the MSBuild file as:

   1:  <PropertyGroup>
   2:  <VS2003_Devenv>$(ProgramFiles)Microsoft Visual Studio .NET 2003Common7IDEdevenv.com</VS2003_Devenv>
   3:  <VS2003_SolutionName>$(SolutionRoot)vs2003VS2003ApplicationVS2003SLN.sln</VS2003_SolutionName>
   4:  <VS2003_Configuration>Debug</VS2003_Configuration>
   5:  </PropertyGroup>
   6:   
   7:   
   8:  <Target Name="AfterCompile">
   9:  <Exec Command="&quot;$(VS2003_Devenv)&quot; &quot;$(VS2003_SolutionName)&quot; /build $(VS2003_Configuration)"/>
  10:   
  11:  <MakeDir
  12:  Directories="$(BinariesRoot)$(VS2003_Configuration)"
  13:  Condition="!Exists('$(BinariesRoot)$(VS2003_Configuration)')" />
  14:   
  15:  <Copy
  16:  SourceFiles="$(SolutionRoot)vs2003VS2003Applicationbin$(VS2003_Configuration)***.*"      
  17:  DestinationFiles="$(SolutionRoot)vs2003VS2003Applicationbin$(VS2003_Configuration)***.* ->'$(BinariesRoot)$(VS2003_Configuration)%(RecursiveDir)%(Filename)%(Extension)')"
  18:  />
  19:  </Target>

Read here for more information about the target names and the MSBuild configuration file.

First declare some variables to use them during the build. (Lines 1 – 5) . Next in the AfterCompile target, use the MSBuild Exec task to build the VS2003 project by invoking the devenv.com program (Lines 9 -10). After that make a directory (using MakeDir task) for the output (if not exists) (Lines 11 – 13). Finally copy (using the Copy task)the output files to the build binaries root (Lines 15 – 18).

Notice that this assumes VS 2003 is installed on the build machine.

Good Luck!

ADO.NET Data Services ("Project Astoria") CTP is Released

Earlier this day I wrote about the release of ASP.NET 3.5 Extensions Preview release . The ASP.NET 3.5 Extensions Preview is a new release that provides new functionality being added to ASP.NET 3.5 and ADO.NET in 2008. This release delivers a set of new features that target:

  1. Enabling High Productivity Data Scenarios – including MVC, Entity Framework, ADO.NET Data Services and dynamic data
  2. Supporting Test Driven Development – including a powerful and extensible MVC framework
  3. Creating the best server for Rich Clients – including Ajax history support and Silverlight controls for ASP.NET

This release also includes the first CTP of the production version of ADO.NET Data Services (aka "Astoria") .

ADO.NET Data Services

ADO.NET Data Services provide new services that find, manipulate and deliver data over the web using simple URIs. Benefits include an easy and flexible way to access data over the web, while enabling the separation of presentation and data access code.

Astoria team blog: http://blogs.msdn.com/astoriateam/default.aspx

ASP.NET 3.5 Extensions Preview Released

The ASP.NET 3.5 Extensions Preview is a preview of new functionality being added to ASP.NET 3.5 and ADO.NET. The release includes an ASP.NET MVC, ASP.NET Dynamic Data, Silverlight controls for ASP.NET, ADO.NET Data Services, Entity Framework runtime, and new features for ASP.NET AJAX.

HTML helpers pages: ASP.NET MVC Preview: Using The MVC UI Helpers

How to Unit Testing with MVC: TDD and Dependency Injection with ASP.NET MVC

Team Explorer 2008 Download

To connect to Team Foundation Server, you must run a separate installer for Team Explorer. This installer is located in the [Drive]:TFC folder on both the Team Suite 2008 media and the Team Foundation Server 2008 media.

Team Explorer 2008  is now also available to download.

Download Visual Studio Team Explorer 2008 (~384mb).

Technorati Tags:

GMAIL New Feature

Do you need help with keyboard shortcuts in Gmail? Just type ? (question mark) and you’ll see a list of the most important keyboard shortcuts. To use it, you need to enable keyword shortcuts in the Settings before using them (the option is disabled by default).

I really like it!

GmailHelp

Technorati Tags: ,

Pro LINQ: Language Integrated Query in C# 2008 – Early Review

LINQ I like LINQ and I posted about it in my blog.

In the last 2 weeks I have been reading the book Pro LINQ: Language Integrated Query in C# 2008  by Joseph C. Rattz, Jr.  | ISBN: 1-59059-789-3 which I have had access to via the Early Access Program as a PDF ebook.

This book provides superb coverage of LINQ where it shows the reader how to leverage all the new LINQ C# 2008 language features including extension methods, lambda expressions, anonymous data types, and partial methods.

The book refers to all kinds of LINQ including LINQ to Objects, LINQ to SQL, LINQ to XML, LINQ to DataSet. The book starts with an introduction of what LINQ is (the first and second chapters, "Hello LINQ" & "C# 3.0 Language Enhancements for LINQ") and builds this more and more throughout the book and the next chapters.  Even if you don’t a proficient C# developer, you’ll find the book useful. It provides a very good high level overview of all the sections, however goes deep into the inner works of LINQ.

The question whether to use LINQ or not is answered: the book gives you an in-depth understanding about LINQ when and where it is required. 

I like the writing style to Joseph: at eye level and very coherent.

If LINQ interesting you and you would like to know it well – I highly recommend you get this book. Once I get the final version of the book, I will give it another read.

You can download the first chapter for free:

http://www.apress.com/book/view/1590597893

Table of Contents

PART 1 Pro LINQ: Language Integrated Query in C# 2008
CHAPTER 1 Hello LINQ
CHAPTER 2 C# 3.0 Language Enhancements for LINQ

PART 2 LINQ to Objects
CHAPTER 3 LINQ to Objects Introduction
CHAPTER 4 Deferred Operators
CHAPTER 5 Nondeferred Operators

PART 3 LINQ to XML
CHAPTER 6 LINQ to XML Introduction
CHAPTER 7 The LINQ to XML API
CHAPTER 8 LINQ to XML Operators
CHAPTER 9 Additional XML Capabilities

PART 4  LINQ to DataSet
CHAPTER 10 LINQ to DataSet Operators
CHAPTER 11 Additional DataSet Capabilities

PART 5 LINQ to SQL
CHAPTER 12 LINQ to SQL Introduction
CHAPTER 13 LINQ to SQL Tips and Tools
CHAPTER 14 LINQ to SQL Database Operations
CHAPTER 15 LINQ to SQL Entity Classes
CHAPTER 16 The DataContext
CHAPTER 17 Concurrency Conflicts
CHAPTER 18 Additional SQL Capabilities

 

Technorati Tags:

Announcing Volta: Web Development Using Only the Materials in the Room

volta Just released from Microsoft Live Labs: Volta.

Volta is another codename project from Microsoft that aims at Web UI experience.

 

The Volta technology preview is a developer toolset that enables you to build multi-tier web applications by applying familiar techniques and patterns. First, design and build your application as a .NET client application, then assign the portions of the application to run on the server and the client tiers late in the development process. The compiler creates cross-browser JavaScript for the client tier, web services for the server tier, and communication,erialization, synchronization, security, and other boilerplate code to tie the tiers together.

See detailed architectural and fundamental description here.

Technorati Tags:
%d bloggers like this: