The SqlVersion task provides the ability to manage multiple build versions in a simple database table.

Valid TaskActions are:

GetVersion (Required: BuildName, DatabaseName Optional: Delimiter, FieldToIncrement, PaddingCount, PaddingDigit Output: Build, Major, Minor, Revision, Version)

Remote Execution Support: Yes

Namespace: MSBuild.ExtensionPack.SqlServer
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 3.5.0.0

Remarks

The following TSql can be used to create the supported table structure:

USE [YOURDATABASENAME]

GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BuildNumbers]') AND type in (N'U'))

DROP TABLE [dbo].[BuildNumbers];

GO

SET ANSI_NULLS ON;

GO

SET QUOTED_IDENTIFIER ON;

GO

SET ANSI_PADDING ON;

GO

CREATE TABLE [dbo].[BuildNumbers](

[SequenceName] [varchar](50) NOT NULL,

[Major] [int] NOT NULL,

[Minor] [int] NOT NULL,

[Build] [int] NOT NULL,

[Increment] [int] NOT NULL,

CONSTRAINT [PK_BuildNumbers_1] PRIMARY KEY CLUSTERED

(

[SequenceName] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY];

GO

SET ANSI_PADDING OFF;

GO

Valid TaskActions are:

GetVersion (Required: BuildName, DatabaseName Optional: FieldToIncrement, Delimiter, PaddingCount, PaddingDigit Output: Major, Minor, Build, Revision, Version)

Remote Execution Support: NA

Examples

Xml Copy imageCopy
<Target Name="BuildNumberOverrideTarget">
    <PropertyGroup>
        <FieldToIncrement Condition=" '$(IncrementalBuild)'=='true' ">4</FieldToIncrement>
        <FieldToIncrement Condition=" '$(IncrementalBuild)'!='true' ">3</FieldToIncrement>
    </PropertyGroup>
    <!-- Get the latest build number without incrementing it -->
    <MSBuild.ExtensionPack.SqlServer.SqlVersion Taskaction="GetVersion" BuildName="V9 Production Build" DatabaseName="Mike">
        <Output TaskParameter="Version" PropertyName="LatestVersion" />
    </MSBuild.ExtensionPack.SqlServer.SqlVersion>
    <Message Text="LatestVersion is: $(LatestVersion)"/>
    <!-- Get the latest build number and increment as necessary -->
    <MSBuild.ExtensionPack.SqlServer.SqlVersion Taskaction="GetVersion" BuildName="V9 Production Build" FieldToIncrement="$(FieldToIncrement)" DatabaseName="Mike">
        <Output TaskParameter="Major" PropertyName="BuildMajor" />
        <Output TaskParameter="Minor" PropertyName="BuildMinor" />
        <Output TaskParameter="Build" PropertyName="BuildBuild" />
        <Output TaskParameter="Revision" PropertyName="BuildRevision" />
    </MSBuild.ExtensionPack.SqlServer.SqlVersion>
    <!-- Override Team Build BuildNumber property -->
    <PropertyGroup>
        <BuildNumber>$(BuildMajor).$(BuildMinor).$(BuildBuild).$(BuildRevision)</BuildNumber>
    </PropertyGroup>
    <Message Text="BuildNumber is: $(BuildNumber)"/>
    <!-- Export values so they can be seen by targets inside CoreCompile -->
    <PropertyGroup>
        <CustomPropertiesForBuild>$(CustomPropertiesForBuild);BuildMajor=$(BuildMajor);BuildMinor=$(BuildMinor);BuildBuild=$(BuildBuild);BuildRevision=$(BuildRevision)</CustomPropertiesForBuild>
    </PropertyGroup>
    <!-- Get the latest build number without incrementing it -->
    <MSBuild.ExtensionPack.SqlServer.SqlVersion Taskaction="GetVersion" BuildName="V9 Production Build" DatabaseName="Mike">
        <Output TaskParameter="Version" PropertyName="LatestVersion" />
    </MSBuild.ExtensionPack.SqlServer.SqlVersion>
    <Message Text="LatestVersion is: $(LatestVersion)"/>
</Target>

Inheritance Hierarchy

System..::..Object
  Microsoft.Build.Utilities..::..Task
    MSBuild.ExtensionPack..::..BaseTask
      MSBuild.ExtensionPack.SqlServer..::..SqlVersion

See Also