MSBuild + Team Build 2008 Presentation

You can download MSBuild & Team Build 2008 presentation.

MSBuild Extension Pack Brings 170 Build Tasks

When MSBuild was first released, it was seen as a stopgap measure. Prior to its introduction, building a non-trivial .NET project from the command line was a daunting challenge. Either command line options have to be carefully laid out or third-party libraries like NAnt have to be brought in.

Recently MSBuild Extension Pack was released on CodePlex. Run by Mike Fourie and a team of 5 developers, this successor to FreeToDev MSBuild Extensions has over 170 different tasks for MSBuild. Many of these tasks support a MachineName argument allowing the actions to be performed on a remote machine.

The team summarizes the tasks into these categories:

  • System Items: Certificates, COM+, Console, Date and Time, Drives, Environment Variables, Event Logs, Files and Folders, GAC, Network, Performance Counters, Registry, Services, Sound
  • Code: Assemblies, CAB Files, Code Signing, File Detokenisation, GUID’s, Mathematics, Strings, Threads, Zip
  • Applications: BizTalk 2006, Email, IIS7, MSBuild, SourceSafe, StyleCop, Team Foundation Server, Visual Basic 6, WMI

Team Build and ClickOnce

The other day I got a question: How can I deploy an app via ClickOnce using Team Build?

There is not out of box way to do that, but we can do it with a simple workaround:

we should overload the target AfterCompile in TFSBuild.Proj to call MSBuild Task Publish and can pass the PublishDir property:

<Target Name="AfterCompile">
  <MSBuild
  Condition=" '@(SolutionToBuild)'!='' "
  Projects="@(SolutionToBuild)"
  Properties="Configuration=%(ConfigurationToBuild.FlavorToBuild);
    Platform=%(ConfigurationToBuild.PlatformToBuild);
    SkipInvalidConfigurations=true;
    VCBuildOverride=$(MSBuildProjectDirectory)TFSBuild.vsprops;
    FxCopDir=$(FxCopDir);OutDir=$(OutDir);
    PublishDir=$(OutDir);
    ReferencePath=$(ReferencePath);
    TeamBuildConstants=$(TeamBuildConstants);
    $(CodeAnalysisOption);PublishDir=\qa1SrvdropspublishedVers "
  Targets="Publish" />
</Target>

Configure Team Foundation Build for an Incremental Build

A question I got today: “How can I configure my Team Build for an incremental build?”.

So, it’s simple.

Team Build 2005

Add the PropertyGroup definition to the end of the TFSBuild.proj file, before the closing </project> tag.

Set the following properties:

   <PropertyGroup>      <SkipClean>true</SkipClean>      <SkipInitializeWorkspace>true</SkipInitializeWorkspace>      <ForceGet>false</ForceGet>   </PropertyGroup>

Team Build 2008

Set IncrementalBuild property to true. To do it, add the PropertyGroup definition to the end of the TFSBuild.proj file, before the closing </project> tag.

   <PropertyGroup>      <IncrementalBuild>true</IncrementalBuild>   </PropertyGroup>

Source – msdn:

Team Build 2005: http://msdn.microsoft.com/en-us/library/aa833876(VS.80).aspx

Team Build 2008: http://msdn.microsoft.com/en-us/library/aa833876.aspx

Microsoft Source Analysis for C#

Microsoft announce the public release of a new developer tool –  Source Analysis for C#.

Inside Microsoft this tool’s name is StyleCop and it enforces code style guidelines on the code we write

Source Analysis comes with a set of default rules analyzers covering approximately 200 best practice rules. These rules are full compatible with the default layout settings in Visual Studio 2005 and Visual Studio 2008.

Specifically, these rules cover the following, in no particular order:

  • Layout of elements, statements, expressions, and query clauses
  • Placement of curly brackets, parenthesis, square brackets, etc
  • Spacing around keywords and operator symbols
  • Line spacing
  • Placement of method parameters within method declarations or method calls
  • Standard ordering of elements within a class
  • Formatting of documentation within element headers and file headers
  • Naming of elements, fields and variables
  • Use of the built-in types
  • Use of access modifiers
  • Allowed contents of files
  • Debugging text

After installation, Source Analysis can be run from within the Visual Studio IDE. You can set this up to be run as a part of your build process as documented here. Since this is plugged in as a MsBuild project you can use it in as a part of Team Foundation Build process as well.

Running Source Analysis:

sca1

And the results are:

sca2

Download it from: http://code.msdn.microsoft.com/sourceanalysis

Read full details:http://blogs.msdn.com/sourceanalysis/archive/2008/05/23/announcing-the-release-of-microsoft-source-analysis.aspx

ALM 403: Control Your Database Lifecycle With Data Dude – Agenda

Next week I’ll give a session at TechEd 2008 In Eilat, Israel. The session will introduce you how you can control your database changes and integrate it into your agile development methodology.

Do you want to control your database changes?

Do you want to test your database with unit test and even run static analysis on it?

Do you want better life and easier deployment of database schema changes to production database?

If one of your answers is YES, come to hear me.

Session Details:

  • Session Name: ALM403: Control your Database Lifecycle with Data Dude
  • Level: 400
  • Time: 8/4/2008, 9:00 AM
  • Location: Hilton Hotel, Ofir-Adom Hall

Session’s Agenda:

  • What is Data Dude?
  • Data Dude Features
  • Test Your Database!
  • Build & Deploy (MSBuild & Team Build)
  • Case Study: nuconomy
  • Q & A
  • Summary

Microsoft opened up the meetings application at http://www.face2facemeeting.com/teched/. If you want to meet me and talk with me on development, WCF, LINQ, ALM or anything else – contact me! I’ll be glad to see you!

Meet you there…

Remove Items From ItemGroups In MSBuild

The ability to remove entries from ItemGroups is one of the new features of MSBuild 3.5.

To remove an Item from an ItemGroup in MSBuild 2.0 you would have to create a new ItemGroup from the old one and skip the Item that you needed removed.

In MSBuild 3.5 we can achieve it by using the Remove parameter.

Example:

<ItemGroup>    <Files Include="a.cs" />    <Files Include="b.cs" />    <Files Include="c.cs" />    <Files Include="d.cs" />    <Files Include="e.cs" />    <Files Include="f.cs" />    <Files Include="g.cs" /></ItemGroup>

Some times we want to restrict some data from this group in a target. In order to do it,  we should use the Remove parameter:

<ItemGroup>    <Files Remove="a.cs" />    <Files Remove="e.cs" />    <Files Remove="f.cs" /></ItemGroup>

Read more at msdn.

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

%d bloggers like this: