0

Automatic CI Versioning using TeamCity and MSBuild

by Jon 4. October 2010 20:33

If you read my first post on getting started with TeamCity, and my follow up post on moving to MSBuild you will have a lovely CI system that builds your solution each you commit your changes.  Whilst this sounds fantastic, unfortunately of the assemblies that are built will all be versioned with the same version that is pulled from the AssemblyInfo.  Luckily it isn't a major change to get MSBuild to update your solution files with the version number stored in TeamCity every time a build occurs by tweaking your MsBuild File: (and installing MsBuild Community Tasks)

<?xml version="1.0" encoding="utf-8" ?> 
<Project  DefaultTargets="ReleaseBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

    <Target Name="ReleaseBuild">

        <Message Text="Set the correct $(BUILD_NUMBER)" /> 
	<FileUpdate Files='AssemblyInfo.vb' 
	  Regex='Version\("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"\)' 
	  ReplacementText='Version("$(BUILD_NUMBER)")' />

	<FileUpdate Files='AssemblyInfo.cs' 
	  Regex='Version\("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"\)' 
	  ReplacementText='Version("$(BUILD_NUMBER)")' />

        <Message Text="Building"/> 
        <MSBuild Projects="ProjectName.sln" Targets="Rebuild" /> 

    </Target>
</Project>

 

Shared Solution Level Assembly InfoThis change uses the FileUpdate Task in MsBuild Community Tasks to be performed on the two specified files, AssemblyInfo.vb and AssemblyInfo.cs.  The Regex will search for the word Version, followed by a valid four digit string version, and replace it with the build version configured in team city.

I use a Solution wide AssemblyInfo file called SolutionAssemblyInfo.vb or SolutionAssemblyInfo.cs to standardise Assembly Information across the solution by using a single shared file.  You can Create this shared file in Visual Studio by Adding a New Item to the Solution Directly, and then after you have created it you link it into each project by clicking on Add existing in each project and pressing the Arrow on the 'Add' Button and selecting 'Add as Link' instead.  This Shared Solution wide file contains the assembly info that is shared across the assemblies, each project will contain the link to shared assembly info file, and the existing assembly info file in the My Project folder.

Tags: , ,

ddd | development | MSSQL Server | Versioning

0

The Easy Way to fix Server Collation in MS SQL Server

by Jon 27. September 2010 21:11

When you have different developers, customers and databases your database collation is bound to get out of sync.  Making sure you have matching collation is important because it can cause problems when it comes to running SQL queries and can impact performance if you are joining text fields.  There isn't an easy way to change the collation across an entire server because the collation is stored against the fields in each table.  I looked at a number of different scripts but found the following script was the easiest way to fix the problem.  Simply set @toCollation to the collation you want in your database, and run the query.  The query will output a List of ALTER COLUMN SQL Queries which you can copy into a query window and execute to fix your database.

declare  @toCollation sysname 

SET    @toCollation = 'Latin1_General_CI_AS' --  Database default collate

SELECT 'ALTER TABLE ' + INFORMATION_SCHEMA.COLUMNS.TABLE_NAME +

       '   ALTER COLUMN ' + COLUMN_NAME + ' ' + DATA_TYPE +

       CASE WHEN CHARACTER_MAXIMUM_LENGTH = -1 then '(max)'

            WHEN DATA_TYPE in ('text','ntext') then ''

            WHEN CHARACTER_MAXIMUM_LENGTH IS NOT NULL 

             THEN '('+(CONVERT(VARCHAR,CHARACTER_MAXIMUM_LENGTH)+')' )

            ELSE isnull(CONVERT(VARCHAR,CHARACTER_MAXIMUM_LENGTH),' ') END

       +' COLLATE ' + @toCollation+ ' ' + CASE IS_NULLABLE

                                           WHEN 'YES' THEN 'NULL'

                                           WHEN 'No' THEN 'NOT NULL' 

END

FROM INFORMATION_SCHEMA.COLUMNS INNER JOIN INFORMATION_SCHEMA.TABLES

ON  INFORMATION_SCHEMA.COLUMNS.TABLE_NAME = INFORMATION_SCHEMA.TABLES.TABLE_NAME

AND INFORMATION_SCHEMA.COLUMNS.TABLE_SCHEMA  = INFORMATION_SCHEMA.TABLES.TABLE_SCHEMA

WHERE DATA_TYPE IN ('varchar' ,'char','nvarchar','nchar','text','ntext')

AND TABLE_TYPE = 'BASE TABLE'

 and COLLATION_NAME <> @toCollation

You will find most of the queries will work, for the queries that dont work due relational joins you can open the table in enterprise manager in design mode and fix the small number of remaining offending fields manually really quickly.  Within moments you have a database with matching collation accross all its tables.

 

Tags: , ,

SQL | MSSQL Server

Powered by BlogEngine.NET 2.0.0.36
Original Design by Laptop Geek, Adapted by onesoft, and finally some tiny tweaks by JonAlb